home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / vibrant / vibwndws.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  128.5 KB  |  5,185 lines  |  [TEXT/R*ch]

  1. /*   vibwndws.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibwndws.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.45 $
  33. *
  34. * File Description: 
  35. *       Vibrant main, event loop, and window functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef WIN_MAC
  51. #include <Resources.h>
  52. #include <Scrap.h>
  53. /*#include <Strings.h>*/
  54. #include <Processes.h>
  55. #include <Events.h> /* keymap, dgg */
  56. #include <AppleEvents.h>
  57. #include <EPPC.h> /* kHighLevelEvent */
  58. #endif
  59.  
  60. #ifdef WIN_MAC
  61. #include <Resources.h>
  62. #ifndef Nlm_WindowTool
  63. #define Nlm_WindowTool  WindowPtr
  64. #endif
  65. #ifndef Nlm_PortTool
  66. #define Nlm_PortTool    GrafPtr
  67. #endif
  68. #ifndef Nlm_ShellTool
  69. #define Nlm_ShellTool   Nlm_Handle
  70. #endif
  71. #ifndef Nlm_MainTool
  72. #define Nlm_MainTool    Nlm_Handle
  73. #endif
  74. #endif
  75.  
  76. #ifdef WIN_MSWIN
  77. #ifndef Nlm_WindowTool
  78. #define Nlm_WindowTool  HWND
  79. #endif
  80. #ifndef Nlm_PortTool
  81. #define Nlm_PortTool    HDC
  82. #endif
  83. #ifndef Nlm_ShellTool
  84. #define Nlm_ShellTool   Nlm_Handle
  85. #endif
  86. #ifndef Nlm_MainTool
  87. #define Nlm_MainTool    Nlm_Handle
  88. #endif
  89. #endif
  90.  
  91. #ifdef WIN_MOTIF
  92. #include <Xm/DialogS.h>
  93. #ifndef Nlm_WindowTool
  94. #define Nlm_WindowTool  Widget
  95. #endif
  96. #ifndef Nlm_PortTool
  97. #define Nlm_PortTool    GC
  98. #endif
  99. #ifndef Nlm_ShellTool
  100. #define Nlm_ShellTool   Widget
  101. #endif
  102. #ifndef Nlm_MainTool
  103. #define Nlm_MainTool    Widget
  104. #endif
  105. #endif
  106.  
  107. typedef  struct  Nlm_windowdata {
  108.   Nlm_WindowTool   handle;
  109.   Nlm_ShellTool    shell;
  110.   Nlm_PortTool     port;
  111.   Nlm_MainTool     main;
  112.   Nlm_RecT         dragArea;
  113.   Nlm_RecT         growArea;
  114.   Nlm_RecT         zoomArea;
  115.   Nlm_WndActnProc  close;
  116.   Nlm_WndActnProc  activate;
  117.   Nlm_WndActnProc  deactivate;
  118.   Nlm_WndActnProc  resize;
  119.   Nlm_DisplaY      charDisplay;
  120.   Nlm_MenuBaR      menuBar;
  121.   Nlm_ButtoN       defaultButton;
  122.   Nlm_Boolean      notYetShown;
  123.   Nlm_Boolean      dying;
  124.   Nlm_CharPtr      title;
  125.   Nlm_VoidPtr      data;
  126.   Nlm_WndFreeProc  cleanup;
  127. } Nlm_WindowData;
  128.  
  129. typedef  struct  Nlm_windowrec {
  130.   Nlm_BoxRec      boxR;
  131.   Nlm_WindowData  window;
  132. } Nlm_WindowRec, PNTR Nlm_WndPtr;
  133.  
  134. Nlm_WindoW   Nlm_desktopWindow;
  135. Nlm_WindoW   Nlm_systemWindow;
  136.  
  137. Nlm_RecT     Nlm_screenRect;
  138.  
  139. Nlm_WindoW   Nlm_theWindow;
  140.  
  141. #ifdef WIN_MAC
  142. EventRecord  Nlm_currentEvent;
  143. #endif
  144.  
  145. #ifdef WIN_MSWIN
  146. WPARAM       Nlm_currentWParam;
  147. HINSTANCE    Nlm_currentHInst;
  148. LPARAM       Nlm_currentLParam;
  149. MSG          Nlm_currentMssg;
  150. int          Nlm_currentId;
  151. HWND         Nlm_currentHwndCtl;
  152. UINT         Nlm_currentCode;
  153. int          Nlm_currentPos;
  154. #endif
  155.  
  156. #ifdef WIN_MOTIF
  157. XEvent        Nlm_currentEvent;
  158. XtAppContext  Nlm_appContext;
  159. XmFontList    Nlm_XfontList;
  160. Widget        Nlm_fileDialogShell;
  161.  
  162. int           argc;
  163. char          **argv;
  164. #endif
  165.  
  166. #ifdef DCLAP
  167.  
  168. /* currently only used in WIN_MOTIF, window creation */
  169. char  Nlm_appname[256];
  170.  
  171. #ifdef WIN_MOTIF
  172.  
  173. /* 
  174.      user can override these w/ .Xresources entry in form of
  175.   appname*resourcename: xxx
  176. -- or --
  177.   Vibrant*resourcename: xxx
  178. */
  179. static String colorXresources[] = {
  180.   "*Foreground:                 #000000000000",
  181.   "*XmScrollBar*Foreground:             #bfbfbfbfbfbf",
  182.   "*XmLabel*Foreground:                 #1d1d15155b5b",
  183.   "*XmToggleButton*Foreground:          #1d1d15155b5b",
  184.   "*XmPushButton*Foreground:            #5b5b00000000",
  185.  
  186.   "*Background:                         #cfcfcfcfcfcf",
  187.  
  188.   "*XmList*Background:             #bfbfbfbfbfbf",
  189.   "*XmText*Background:                 #bfbfbfbfbfbf",
  190.   "*XmSelectionBox*Background:         #bfbfbfbfbfbf",
  191.   "*XmMessageBox*Background:         #bfbfbfbfbfbf",
  192.   "*XmTextField*Background:         #9c9c9c9c9c9c",
  193.  
  194.   "*TopShadowColor:                     #e7e7e7e7e7e7",
  195.   "*XmList*TopShadowColor:              #e7e7e7e7e7e7",
  196.   "*XmText*TopShadowColor:              #e7e7e7e7e7e7",
  197.   "*XmSelectionBox*TopShadowColor:      #e7e7e7e7e7e7",
  198.   "*XmMessageBox*TopShadowColor:        #e7e7e7e7e7e7",
  199.   
  200.   "*TroughColor:     #646464646464",
  201.   "*SelectColor:            #ffffffff0000",
  202.   "*HighlightColor:        #bfbfbfbfbfbf",
  203.   NULL,
  204. };
  205.  
  206. static String bwXresources[] = {
  207.   "*Foreground:  black",
  208.   "*Background:  white",
  209.   NULL,
  210. };
  211.  
  212. #endif
  213.  
  214. #endif  /* DCLAP */
  215.  
  216.  
  217. Nlm_WindowTool  Nlm_currentWindowTool;
  218.  
  219. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  220.  
  221. static Nlm_GphPrcsPtr  documentProcs;
  222. static Nlm_GphPrcsPtr  fixedProcs;
  223. static Nlm_GphPrcsPtr  frozenProcs;
  224. static Nlm_GphPrcsPtr  roundProcs;
  225. static Nlm_GphPrcsPtr  alertProcs;
  226. static Nlm_GphPrcsPtr  modalProcs;
  227. static Nlm_GphPrcsPtr  floatingProcs;
  228. static Nlm_GphPrcsPtr  shadowProcs;
  229. static Nlm_GphPrcsPtr  plainProcs;
  230. static Nlm_GphPrcsPtr  desktopProcs;
  231. static Nlm_GphPrcsPtr  systemProcs;
  232.  
  233. static Nlm_Boolean     quitProgram;
  234. static Nlm_Boolean     getArgsBoxUp;
  235. static Nlm_Boolean     getArgsOk;
  236.  
  237. static Nlm_WindoW      recentWindow = NULL;
  238. static Nlm_WindowData  recentWindowData;
  239.  
  240. static Nlm_WindoW      chosenWindow;
  241. static Nlm_WindoW      frontWindow;
  242. static Nlm_WindoW      theActiveWindow;
  243.  
  244. static Nlm_WindoW      dyingWindow;
  245. static Nlm_RecT        screenBitBounds;
  246. static Nlm_Boolean     inNotice;
  247.  
  248. static Nlm_VoidProc    timerAction;
  249. static Nlm_KeyProc     keyAction;
  250.  
  251. #ifdef WIN_MAC
  252. static Cursor       cross;
  253. static Cursor       iBeam;
  254. static Cursor       plus;
  255. static Cursor       watch;
  256. static Nlm_Int4     lastTimerTime;
  257. static Nlm_Boolean  hasColorQD = FALSE;
  258. static Str255       apName;
  259. static Handle       apParam;
  260. static short        apRefNum;
  261. #endif
  262.  
  263. #ifdef WIN_MSWIN
  264. static HCURSOR       currentCursor;
  265. static UINT          timerID;
  266. static Nlm_Char      windowclass [32];
  267. static int           discard_count = 0;
  268. static LRESULT       mainwndrsult;
  269. static Nlm_Boolean   handlechar;
  270. #endif
  271.  
  272. #ifdef WIN_MOTIF
  273. static Cursor        currentCursor;
  274. static Cursor        arrow;
  275. static Cursor        cross;
  276. static Cursor        iBeam;
  277. static Cursor        plus;
  278. static Cursor        watch;
  279. static XFontStruct   *font;
  280. static XtIntervalId  windowTimer;
  281. static GC            firstGC;
  282. static int           statargc;
  283. static char          **statargv;
  284. #endif
  285.  
  286. static void Nlm_LoadWindowData (Nlm_WindoW w, Nlm_WindowTool hdl,
  287.                                 Nlm_ShellTool shl, Nlm_PortTool prt,
  288.                                 Nlm_MainTool man, Nlm_RectPtr drag,
  289.                                 Nlm_RectPtr grow, Nlm_RectPtr zoom,
  290.                                 Nlm_WndActnProc closeProc, Nlm_WndActnProc actProc,
  291.                                 Nlm_WndActnProc deactProc, Nlm_WndActnProc resiz,
  292.                                 Nlm_DisplaY charDisp, Nlm_MenuBaR mnuBar,
  293.                                 Nlm_ButtoN dfltBtn, Nlm_Boolean notYet,
  294.                                 Nlm_Boolean die, Nlm_CharPtr ttl,
  295.                                 Nlm_VoidPtr dat, Nlm_WndFreeProc cln)
  296.  
  297. {
  298.   Nlm_WindowData  PNTR wdptr;
  299.   Nlm_WndPtr      wp;
  300.  
  301.   if (w != NULL) {
  302.     wp = (Nlm_WndPtr) Nlm_HandLock (w);
  303.     wdptr = &(wp->window);
  304.     wdptr->handle = hdl;
  305.     wdptr->shell = shl;
  306.     wdptr->port = prt;
  307.     wdptr->main = man;
  308.     if (drag != NULL) {
  309.       wdptr->dragArea = *drag;
  310.     } else {
  311.       Nlm_LoadRect (&(wdptr->dragArea), 0, 0, 0, 0);
  312.     }
  313.     if (grow != NULL) {
  314.       wdptr->growArea = *grow;
  315.     } else {
  316.       Nlm_LoadRect (&(wdptr->growArea), 0, 0, 0, 0);
  317.     }
  318.     if (zoom != NULL) {
  319.       wdptr->zoomArea = *zoom;
  320.     } else {
  321.       Nlm_LoadRect (&(wdptr->zoomArea), 0, 0, 0, 0);
  322.     }
  323.     wdptr->close = closeProc;
  324.     wdptr->activate = actProc;
  325.     wdptr->deactivate = deactProc;
  326.     wdptr->resize = resiz;
  327.     wdptr->charDisplay = charDisp;
  328.     wdptr->menuBar = mnuBar;
  329.     wdptr->defaultButton = dfltBtn;
  330.     wdptr->notYetShown = notYet;
  331.     wdptr->dying = die;
  332.     wdptr->title = ttl;
  333.     wdptr->data = dat;
  334.     wdptr->cleanup = cln;
  335.     Nlm_HandUnlock (w);
  336.     recentWindow = NULL;
  337.   }
  338. }
  339.  
  340. static void Nlm_SetWindowData (Nlm_WindoW w, Nlm_WindowData * wdata)
  341.  
  342. {
  343.   Nlm_WndPtr  wp;
  344.  
  345.   if (w != NULL && wdata != NULL) {
  346.     wp = (Nlm_WndPtr) Nlm_HandLock (w);
  347.     wp->window = *wdata;
  348.     Nlm_HandUnlock (w);
  349.     recentWindow = w;
  350.     recentWindowData = *wdata;
  351.   }
  352. }
  353.  
  354. static void Nlm_GetWindowData (Nlm_WindoW w, Nlm_WindowData * wdata)
  355.  
  356. {
  357.   Nlm_WndPtr  wp;
  358.  
  359.   if (w != NULL && wdata != NULL) {
  360.     if (w == recentWindow && NLM_RISKY) {
  361.       *wdata = recentWindowData;
  362.     } else {
  363.       wp = (Nlm_WndPtr) Nlm_HandLock (w);
  364.       *wdata = wp->window;
  365.       Nlm_HandUnlock (w);
  366.       recentWindow = w;
  367.       recentWindowData = *wdata;
  368.     }
  369.   }
  370. }
  371.  
  372. static Nlm_WindowTool Nlm_GetWindowPtr (Nlm_WindoW w)
  373.  
  374. {
  375.   Nlm_WindowTool  rsult;
  376.   Nlm_WindowData  wdata;
  377.  
  378.   rsult = NULL;
  379.   if (w != NULL) {
  380.     Nlm_GetWindowData (w, &wdata);
  381.     rsult = wdata.handle;
  382.   }
  383.   return rsult;
  384. }
  385.  
  386. extern Nlm_ShellTool Nlm_GetWindowShell (Nlm_WindoW w)
  387.  
  388. {
  389.   Nlm_ShellTool   rsult;
  390.   Nlm_WindowData  wdata;
  391.  
  392.   rsult = NULL;
  393.   if (w != NULL) {
  394.     Nlm_GetWindowData (w, &wdata);
  395.     rsult = wdata.shell;
  396.   }
  397.   return rsult;
  398. }
  399.  
  400. static Nlm_PortTool Nlm_GetWindowPort (Nlm_WindoW w)
  401.  
  402. {
  403.   Nlm_PortTool    rsult;
  404.   Nlm_WindowData  wdata;
  405.  
  406.   rsult = NULL;
  407.   if (w != NULL) {
  408.     Nlm_GetWindowData (w, &wdata);
  409.     rsult = wdata.port;
  410.   }
  411.   return rsult;
  412. }
  413.  
  414. static Nlm_MainTool Nlm_GetWindowMain (Nlm_WindoW w)
  415.  
  416. {
  417.   Nlm_MainTool    rsult;
  418.   Nlm_WindowData  wdata;
  419.  
  420.   rsult = NULL;
  421.   if (w != NULL) {
  422.     Nlm_GetWindowData (w, &wdata);
  423.     rsult = wdata.main;
  424.   }
  425.   return rsult;
  426. }
  427.  
  428. extern void Nlm_SetWindowCharDisplay (Nlm_WindoW w, Nlm_DisplaY d)
  429.  
  430. {
  431.   Nlm_WindowData  wdata;
  432.  
  433.   if (w != NULL) {
  434.     Nlm_GetWindowData (w, &wdata);
  435.     wdata.charDisplay = d;
  436.     Nlm_SetWindowData (w, &wdata);
  437.   }
  438. }
  439.  
  440. extern Nlm_DisplaY Nlm_GetWindowCharDisplay (Nlm_WindoW w)
  441.  
  442. {
  443.   Nlm_DisplaY     rsult;
  444.   Nlm_WindowData  wdata;
  445.  
  446.   rsult = NULL;
  447.   if (w != NULL) {
  448.     Nlm_GetWindowData (w, &wdata);
  449.     rsult = wdata.charDisplay;
  450.   }
  451.   return rsult;
  452. }
  453.  
  454. extern void Nlm_SetWindowMenuBar (Nlm_WindoW w, Nlm_MenuBaR mb)
  455.  
  456. {
  457.   Nlm_WindowData  wdata;
  458.  
  459.   if (w != NULL) {
  460.     Nlm_GetWindowData (w, &wdata);
  461.     wdata.menuBar = mb;
  462.     Nlm_SetWindowData (w, &wdata);
  463.   }
  464. }
  465.  
  466. extern Nlm_MenuBaR Nlm_GetWindowMenuBar (Nlm_WindoW w)
  467.  
  468. {
  469.   Nlm_MenuBaR     rsult;
  470.   Nlm_WindowData  wdata;
  471.  
  472.   rsult = NULL;
  473.   if (w != NULL) {
  474.     Nlm_GetWindowData (w, &wdata);
  475.     rsult = wdata.menuBar;
  476.   }
  477.   return rsult;
  478. }
  479.  
  480. extern void Nlm_SetWindowDefaultButton (Nlm_WindoW w, Nlm_ButtoN b)
  481.  
  482. {
  483.   Nlm_WindowData  wdata;
  484.  
  485.   if (w != NULL) {
  486.     Nlm_GetWindowData (w, &wdata);
  487.     wdata.defaultButton = b;
  488.     Nlm_SetWindowData (w, &wdata);
  489.   }
  490. }
  491.  
  492. extern Nlm_ButtoN Nlm_GetWindowDefaultButton (Nlm_WindoW w)
  493.  
  494. {
  495.   Nlm_ButtoN      rsult;
  496.   Nlm_WindowData  wdata;
  497.  
  498.   rsult = NULL;
  499.   if (w != NULL) {
  500.     Nlm_GetWindowData (w, &wdata);
  501.     rsult = wdata.defaultButton;
  502.   }
  503.   return rsult;
  504. }
  505.  
  506. static void Nlm_SetNotYetShown (Nlm_WindoW w, Nlm_Boolean notYet)
  507.  
  508. {
  509.   Nlm_WindowData  wdata;
  510.  
  511.   if (w != NULL) {
  512.     Nlm_GetWindowData (w, &wdata);
  513.     wdata.notYetShown = notYet;
  514.     Nlm_SetWindowData (w, &wdata);
  515.   }
  516. }
  517.  
  518. extern Nlm_Boolean Nlm_WindowHasBeenShown (Nlm_WindoW w)
  519.  
  520. {
  521.   Nlm_Boolean     rsult;
  522.   Nlm_WindowData  wdata;
  523.  
  524.   rsult = FALSE;
  525.   if (w != NULL) {
  526.     Nlm_GetWindowData (w, &wdata);
  527.     rsult = (Nlm_Boolean) (! wdata.notYetShown);
  528.   }
  529.   return rsult;
  530. }
  531.  
  532. static void Nlm_SetWindowDying (Nlm_WindoW w, Nlm_Boolean die)
  533.  
  534. {
  535.   Nlm_WindowData  wdata;
  536.  
  537.   if (w != NULL) {
  538.     Nlm_GetWindowData (w, &wdata);
  539.     wdata.dying = die;
  540.     Nlm_SetWindowData (w, &wdata);
  541.   }
  542. }
  543.  
  544. extern Nlm_Boolean Nlm_IsWindowDying (Nlm_WindoW w)
  545.  
  546. {
  547.   Nlm_Boolean     rsult;
  548.   Nlm_WindowData  wdata;
  549.  
  550.   rsult = FALSE;
  551.   if (w != NULL) {
  552.     Nlm_GetWindowData (w, &wdata);
  553.     rsult = wdata.dying;
  554.   }
  555.   return rsult;
  556. }
  557.  
  558. extern Nlm_WindoW Nlm_GetParentWindow (Nlm_GraphiC a)
  559.  
  560. {
  561.   Nlm_GraphiC  g;
  562.   Nlm_GraphiC  p;
  563.  
  564.   g = a;
  565.   if (a != NULL) {
  566.     p = Nlm_GetParent (g);
  567.     while (p != NULL) {
  568.       g = p;
  569.       p = Nlm_GetParent (g);
  570.     }
  571.   }
  572.   return (Nlm_WindoW) g;
  573. }
  574.  
  575. extern Nlm_WindoW Nlm_ParentWindow (Nlm_Handle a)
  576.  
  577. {
  578.   return Nlm_GetParentWindow ((Nlm_GraphiC) a);
  579. }
  580.  
  581. extern Nlm_WindowTool Nlm_ParentWindowPtr (Nlm_GraphiC a)
  582.  
  583. {
  584.   Nlm_WindowTool  rsult;
  585.   Nlm_WindoW      w;
  586.  
  587.   rsult = NULL;
  588.   if (a != NULL) {
  589.     w = Nlm_GetParentWindow (a);
  590.     rsult = Nlm_GetWindowPtr (w);
  591.   }
  592.   return rsult;
  593. }
  594.  
  595. extern Nlm_PortTool Nlm_ParentWindowPort (Nlm_GraphiC a)
  596.  
  597. {
  598.   Nlm_PortTool  rsult;
  599.   Nlm_WindoW    w;
  600.  
  601.   rsult = NULL;
  602.   if (a != NULL) {
  603.     w = Nlm_GetParentWindow (a);
  604.     rsult = Nlm_GetWindowPort (w);
  605.   }
  606.   return rsult;
  607. }
  608.  
  609. extern Nlm_MainTool Nlm_ParentWindowMain (Nlm_GraphiC a)
  610.  
  611. {
  612.   Nlm_MainTool  rsult;
  613.   Nlm_WindoW    w;
  614.  
  615.   rsult = NULL;
  616.   if (a != NULL) {
  617.     w = Nlm_GetParentWindow (a);
  618.     rsult = Nlm_GetWindowMain (w);
  619.   }
  620.   return rsult;
  621. }
  622.  
  623. extern Nlm_ShellTool Nlm_ParentWindowShell (Nlm_GraphiC a)
  624.  
  625. {
  626.   Nlm_ShellTool  rsult;
  627.   Nlm_WindoW     w;
  628.  
  629.   rsult = NULL;
  630.   if (a != NULL) {
  631.     w = Nlm_GetParentWindow (a);
  632.     rsult = Nlm_GetWindowShell (w);
  633.   }
  634.   return rsult;
  635. }
  636.  
  637. extern Nlm_WindoW Nlm_SavePortIfNeeded (Nlm_GraphiC a, Nlm_Boolean savePort)
  638.  
  639. {
  640.   Nlm_WindoW  newwindow;
  641.   Nlm_WindoW  oldwindow;
  642.   Nlm_WindoW  rsult;
  643.  
  644.   rsult = NULL;
  645.   if (a != NULL && savePort) {
  646.     savePort = Nlm_GetAllParentsVisible (a);
  647.     if (savePort) {
  648.       oldwindow = Nlm_CurrentWindow ();
  649.       newwindow = Nlm_GetParentWindow (a);
  650.       savePort = (Nlm_Boolean) (oldwindow != newwindow);
  651.       if (savePort) {
  652.         Nlm_UseWindow (newwindow);
  653.         rsult = oldwindow;
  654.       }
  655.     }
  656.   }
  657.   return rsult;
  658. }
  659.  
  660. extern Nlm_WindoW Nlm_SavePort (Nlm_Handle a)
  661.  
  662. {
  663.   return Nlm_SavePortIfNeeded ((Nlm_GraphiC) a, TRUE);
  664. }
  665.  
  666. extern void Nlm_RestorePort (Nlm_WindoW w)
  667.  
  668. {
  669. #ifndef DCLAP
  670.     /* !! dclap doesn't want to be redrawing all over the place like this does ! */
  671.   Nlm_Update ();
  672. #endif
  673.   if (w != NULL) {
  674.     Nlm_UseWindow (w);
  675.   }
  676. }
  677.  
  678. extern void Nlm_SetClose (Nlm_WindoW w, Nlm_WndActnProc cls)
  679.  
  680. {
  681.   Nlm_WindowData  wdata;
  682.  
  683.   if (w != NULL) {
  684.     Nlm_GetWindowData (w, &wdata);
  685.     wdata.close = cls;
  686.     Nlm_SetWindowData (w, &wdata);
  687.   }
  688. }
  689.  
  690. extern void Nlm_SetActivate (Nlm_WindoW w, Nlm_WndActnProc act)
  691.  
  692. {
  693.   Nlm_WindowData  wdata;
  694.  
  695.   if (w != NULL) {
  696.     Nlm_GetWindowData (w, &wdata);
  697.     wdata.activate = act;
  698.     Nlm_SetWindowData (w, &wdata);
  699.   }
  700. }
  701.  
  702. extern void Nlm_SetDeactivate (Nlm_WindoW w, Nlm_WndActnProc deact)
  703.  
  704. {
  705.   Nlm_WindowData  wdata;
  706.  
  707.   if (w != NULL) {
  708.     Nlm_GetWindowData (w, &wdata);
  709.     wdata.deactivate = deact;
  710.     Nlm_SetWindowData (w, &wdata);
  711.   }
  712. }
  713.  
  714. extern void Nlm_SetResize (Nlm_WindoW w, Nlm_WndActnProc resiz)
  715.  
  716. {
  717.   Nlm_WindowData  wdata;
  718.  
  719.   if (w != NULL) {
  720.     Nlm_GetWindowData (w, &wdata);
  721.     wdata.resize = resiz;
  722.     Nlm_SetWindowData (w, &wdata);
  723.   }
  724. }
  725.  
  726. extern void Nlm_SetWindowExtra (Nlm_WindoW w, Nlm_VoidPtr data, Nlm_WndFreeProc cleanup)
  727.  
  728. {
  729.   Nlm_WindowData  wdata;
  730.  
  731.   if (w != NULL) {
  732.     Nlm_GetWindowData (w, &wdata);
  733.     wdata.data = data;
  734.     wdata.cleanup = cleanup;
  735.     Nlm_SetWindowData (w, &wdata);
  736.   }
  737. }
  738.  
  739. extern Nlm_VoidPtr Nlm_GetWindowExtra (Nlm_WindoW w)
  740.  
  741. {
  742.   Nlm_WindowData  wdata;
  743.  
  744.   if (w != NULL) {
  745.     Nlm_GetWindowData (w, &wdata);
  746.     return wdata.data;
  747.   } else {
  748.     return NULL;
  749.   }
  750. }
  751.  
  752. static void Nlm_ClearKeys (void)
  753.  
  754. {
  755.   Nlm_cmmdKey = FALSE;
  756.   Nlm_ctrlKey = FALSE;
  757.   Nlm_optKey = FALSE;
  758.   Nlm_shftKey = FALSE;
  759.   Nlm_dblClick = FALSE;
  760. }
  761.  
  762. static Nlm_WindoW Nlm_FindWindowRec (Nlm_WindowTool wptr)
  763.  
  764. {
  765.   Nlm_WindoW      w;
  766. #ifdef WIN_MAC
  767.   Nlm_WindowData  wdata;
  768. #endif
  769.  
  770. #ifdef WIN_MAC
  771.   Nlm_GetWindowData (Nlm_systemWindow, &wdata);
  772.   wdata.handle = wptr;
  773.   Nlm_SetWindowData (Nlm_systemWindow, &wdata);
  774. #endif
  775.   w = Nlm_desktopWindow;
  776.   while (w != NULL && Nlm_ParentWindowPtr ((Nlm_GraphiC) w) != wptr) {
  777.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  778.   }
  779.   if (w == NULL) {
  780.     w = Nlm_desktopWindow;
  781.   }
  782.   return w;
  783. }
  784.  
  785. static void Nlm_SetWindowTitle (Nlm_GraphiC w, Nlm_Int2 item,
  786.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  787.  
  788.  
  789. {
  790.   Nlm_Char        temp [256];
  791.   Nlm_WindowTool  wptr;
  792. #ifdef WIN_MOTIF
  793.   Nlm_ShellTool   shl;
  794.   Nlm_WindowData  wdata;
  795. #endif
  796.  
  797.   wptr = Nlm_ParentWindowPtr (w);
  798.   Nlm_StringNCpy (temp, title, sizeof (temp));
  799. #ifdef WIN_MAC
  800.   Nlm_CtoPstr (temp);
  801.   SetWTitle (wptr, (StringPtr) temp);
  802. #endif
  803. #ifdef WIN_MSWIN
  804.   SetWindowText (wptr, temp);
  805. #endif
  806. #ifdef WIN_MOTIF
  807.   shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  808.   XtVaSetValues (shl, XmNtitle, temp, NULL);
  809.   XSync (Nlm_currentXDisplay, FALSE);
  810.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  811.   if (wdata.title != NULL) {
  812.     wdata.title = (Nlm_CharPtr) Nlm_MemFree (wdata.title);
  813.   }
  814.   wdata.title = Nlm_StringSave (title);
  815.   Nlm_SetWindowData ((Nlm_WindoW) w, &wdata);
  816. #endif
  817. }
  818.  
  819. static void Nlm_GetWindowTitle (Nlm_GraphiC w, Nlm_Int2 item,
  820.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  821.  
  822. {
  823.   Nlm_Char        temp [256];
  824.   Nlm_WindowTool  wptr;
  825. #ifdef WIN_MOTIF
  826.   Nlm_WindowData  wdata;
  827. #endif
  828.  
  829.   wptr = Nlm_ParentWindowPtr (w);
  830.   temp [0] = '\0';
  831. #ifdef WIN_MAC
  832.   GetWTitle (wptr, (StringPtr) temp);
  833.   Nlm_PtoCstr (temp);
  834. #endif
  835. #ifdef WIN_MSWIN
  836.   GetWindowText (wptr, temp, sizeof (temp));
  837. #endif
  838. #ifdef WIN_MOTIF
  839.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  840.   Nlm_StringNCpy (temp, wdata.title, sizeof (temp));
  841. #endif
  842.   Nlm_StringNCpy (title, temp, maxsize);
  843. }
  844.  
  845. static Nlm_WindoW Nlm_MakeWindowLink (Nlm_RectPtr r, Nlm_Int2 recordSize,
  846.                                       Nlm_GphPrcs PNTR classPtr)
  847.  
  848. {
  849.   Nlm_GraphiC  n;
  850.   Nlm_WindoW   w;
  851.  
  852.   w = (Nlm_WindoW) Nlm_HandNew (recordSize);
  853.   if (w != NULL) {
  854.     n = Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  855.     Nlm_LoadGraphicData ((Nlm_GraphiC) w, n, NULL, NULL, NULL,
  856.                          classPtr, NULL, r, TRUE, FALSE);
  857.     if (Nlm_nextIdNumber < 32767) {
  858.       Nlm_nextIdNumber++;
  859.     }
  860.     Nlm_SetNext ((Nlm_GraphiC) Nlm_desktopWindow, (Nlm_GraphiC) w);
  861.   }
  862.   return w;
  863. }
  864.  
  865. #ifdef WIN_MAC
  866. extern void Nlm_SetUpdateRegion (WindowPtr wptr)
  867.  
  868. {
  869.   RgnPtr  rptr;
  870.  
  871.   if (wptr != NULL) {
  872.     CopyRgn (wptr->visRgn, (Nlm_RgnTool) Nlm_updateRgn);
  873.     HLock ((Handle) Nlm_updateRgn);
  874.     rptr = (RgnPtr) *((Handle) Nlm_updateRgn);
  875.     Nlm_RectToolToRecT (&(rptr->rgnBBox), &Nlm_updateRect);
  876.     HUnlock ((Handle) Nlm_updateRgn);
  877.   }
  878. }
  879. #endif
  880.  
  881. #ifdef WIN_MOTIF
  882. void WindowCloseCallback (Widget wd, XtPointer client_data, XtPointer call_data)
  883.  
  884. {
  885.   Nlm_WndActnProc  cls;
  886.   Nlm_WindoW       w;
  887.   Nlm_WindowData   wdata;
  888.  
  889.   w = (Nlm_WindoW) client_data;
  890.   Nlm_GetWindowData (w, &wdata);
  891.   cls = wdata.close;
  892.   if (cls != NULL) {
  893.     cls (w);
  894.   }
  895. }
  896.  
  897. void WindowResizeCallback (Widget wd, XtPointer client_data,
  898.                            XEvent *ev, Boolean *contin)
  899.  
  900. {
  901.   XConfigureEvent  *event;
  902.   Nlm_RecT         r;
  903.   Nlm_WndActnProc  resize;
  904.   Nlm_RectTool     rtool;
  905.   Nlm_WindoW       w;
  906.   Nlm_WindowData   wdata;
  907.  
  908.   event = (XConfigureEvent *) ev;
  909.   if (event->type != ConfigureNotify) {
  910.     return;
  911.   }
  912.   w = (Nlm_WindoW) client_data;
  913.   Nlm_GetWindowData (w, &wdata);
  914.   rtool.x = event->x;
  915.   rtool.y = event->y;
  916.   rtool.width = event->width;
  917.   rtool.height = event->height;
  918.   Nlm_RectToolToRecT (&rtool, &r);
  919.   Nlm_SetRect ((Nlm_GraphiC) w, &r);
  920.   if (Nlm_WindowHasBeenShown (w) && Nlm_GetVisible ((Nlm_GraphiC) w)) {
  921.     resize = wdata.resize;
  922.     if (resize != NULL) {
  923.       resize (w);
  924.     }
  925.   }
  926. }
  927. #endif
  928.  
  929. #define DOCUMENT_STYLE 1
  930. #define FIXED_STYLE    2
  931. #define FROZEN_STYLE   3
  932. #define ROUND_STYLE    4
  933. #define ALERT_STYLE    5
  934. #define MODAL_STYLE    6
  935. #define FLOATING_STYLE 7
  936. #define SHADOW_STYLE   8
  937. #define PLAIN_STYLE    9
  938.  
  939. static void Nlm_NewWindow (Nlm_WindoW w, Nlm_Int2 type, Nlm_Int2 procID,
  940.                            Nlm_Boolean goAway, Nlm_CharPtr windowClass,
  941.                            Nlm_Uint4 style, Nlm_CharPtr title,
  942.                            Nlm_WndActnProc close, Nlm_WndActnProc resize)
  943.  
  944. {
  945.   Nlm_ShellTool   dlg;
  946.   Nlm_RecT        drag;
  947.   Nlm_RecT        grow;
  948.   Nlm_Int2        hsb;
  949.   Nlm_MainTool    man;
  950.   Nlm_Int2        margin;
  951.   Nlm_RecT        p;
  952.   Nlm_PortTool    prt;
  953.   Nlm_PoinT       pt;
  954.   Nlm_RecT        r;
  955.   Nlm_ShellTool   shl;
  956.   Nlm_Int2        spacing;
  957.   Nlm_Char        temp [256];
  958.   Nlm_CharPtr     ttl;
  959.   Nlm_Int2        vsb;
  960.   Nlm_WindowTool  wptr;
  961.   Nlm_RecT        zoom;
  962. #ifdef WIN_MAC
  963.   Nlm_WindowTool  behindNone;
  964.   Nlm_RectTool    rtool;
  965. #endif
  966. #ifdef WIN_MOTIF
  967.   Atom            atom;
  968.   Cardinal        n;
  969.   Arg             wargs [15];
  970.   int             screen_num;
  971. #endif
  972.  
  973.   if (title != NULL && title [0] != '\0') {
  974.     Nlm_StringNCpy (temp, title, sizeof (temp));
  975.   } else {
  976.     temp [0] = '\0';
  977.   }
  978. #ifdef WIN_MAC
  979.   Nlm_CtoPstr (temp);
  980. #endif
  981.   Nlm_LoadRect (&r, 50, 50, 150, 150);
  982. #ifdef WIN_MOTIF
  983.   r = Nlm_screenRect;
  984.   Nlm_InsetRect (&r, 50, 50);
  985. #endif
  986.   Nlm_GetRect ((Nlm_GraphiC) w, &p);
  987.   margin = 10;
  988.   spacing = 10;
  989.   if (p.right < 0) {
  990.     margin = -p.right;
  991.   }
  992.   if (p.bottom < 0) {
  993.     spacing = -p.bottom;
  994.   }
  995.   if (p.right >= 0 || p.bottom >= 0) {
  996.     r = p;
  997.     r.bottom = r.top + r.bottom;
  998.     r.right = r.left + r.right;
  999.   }
  1000. #ifdef DCLAP
  1001.     /* this is general adjustment for bad rect values */
  1002.     if (r.bottom - r.top < 20) r.bottom = r.top + 20;
  1003.   if (r.right - r.left < 20) r.right= r.left + 20;
  1004. #endif
  1005.   Nlm_LoadPt (&pt, margin, margin);
  1006.   shl = NULL;
  1007.   dlg = NULL;
  1008.   wptr = NULL;
  1009.   prt = NULL;
  1010.   man = NULL;
  1011.   ttl = NULL;
  1012.   hsb = 0;
  1013.   vsb = 0;
  1014. #ifdef WIN_MAC
  1015.   wptr = (Nlm_WindowTool) Nlm_MemNew (sizeof (WindowRecord));
  1016.   behindNone = (Nlm_WindowTool) (-1);
  1017.   TextFont (0);
  1018.   TextSize (0);
  1019.   Nlm_RecTToRectTool (&r, &rtool);
  1020.   if (close == NULL) {
  1021.     goAway = FALSE;
  1022.   }
  1023.   if (hasColorQD) {
  1024.     wptr = (WindowPtr) NewCWindow ((Ptr) wptr, &rtool, (StringPtr) temp,
  1025.                                    FALSE, procID,(Nlm_WindowTool) behindNone,
  1026.                                    goAway, 0);
  1027.   } else {
  1028.     wptr = NewWindow ((Ptr) wptr, &rtool, (StringPtr) temp, FALSE, procID,
  1029.                       (Nlm_WindowTool) behindNone, goAway, 0);
  1030.   }
  1031.   SetPort (wptr);
  1032.   Nlm_currentWindowTool = wptr;
  1033.   prt = (Nlm_PortTool) wptr;
  1034.   Nlm_SetUpdateRegion (wptr);
  1035.   PenNormal ();
  1036.   MoveTo (2, 10);
  1037.   if (hasColorQD) {
  1038.     GetForeColor (&Nlm_RGBforeColor);
  1039.     GetBackColor (&Nlm_RGBbackColor);
  1040.   }
  1041. #endif
  1042. #ifdef WIN_MSWIN
  1043.   if (close == NULL) {
  1044.     style &= ~WS_SYSMENU;
  1045.   }
  1046.   if (type == FLOATING_STYLE) {
  1047.     wptr = CreateWindowEx (WS_EX_TOPMOST, windowClass, temp, style,
  1048.                          r.left, r.top, r.right - r.left,
  1049.                          r.bottom - r.top, NULL, NULL,
  1050.                          Nlm_currentHInst, NULL);
  1051.   } else if (type == MODAL_STYLE) {
  1052.     wptr = CreateWindowEx (WS_EX_DLGMODALFRAME, windowClass, temp, style,
  1053.                          r.left, r.top, r.right - r.left,
  1054.                          r.bottom - r.top, NULL, NULL,
  1055.                          Nlm_currentHInst, NULL);
  1056.   } else {
  1057.     wptr = CreateWindow (windowClass, temp, style,
  1058.                          r.left, r.top, r.right - r.left,
  1059.                          r.bottom - r.top, NULL, NULL,
  1060.                          Nlm_currentHInst, NULL);
  1061.   }
  1062.   if (wptr != NULL) {
  1063.     SetProp (wptr, (LPSTR) "Nlm_VibrantProp", (Nlm_HandleTool) w);
  1064.   }
  1065.   prt = GetDC (wptr);
  1066.   Nlm_currentHDC = prt;
  1067.   Nlm_currentHWnd = wptr;
  1068. #endif
  1069. #ifdef WIN_MOTIF
  1070.   n = 0;
  1071.   XtSetArg (wargs[n], XmNtitle, temp); n++;
  1072.   XtSetArg (wargs[n], XmNx, (Position) r.left); n++;
  1073.   XtSetArg (wargs[n], XmNy, (Position) r.top); n++;
  1074.   XtSetArg (wargs[n], XmNdefaultFontList, Nlm_XfontList); n++;
  1075.   XtSetArg (wargs[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  1076. #ifdef DCLAP
  1077.     /* we want to stick app name here, thru some new vibrant global var */  
  1078.   shl = XtAppCreateShell (Nlm_appname, (String) "Vibrant",
  1079.                           applicationShellWidgetClass,
  1080.                           Nlm_currentXDisplay, wargs, n);
  1081. #else
  1082.   shl = XtAppCreateShell ((String) NULL, (String) "Vibrant",
  1083.                           applicationShellWidgetClass,
  1084.                           Nlm_currentXDisplay, wargs, n);
  1085. #endif
  1086.   dlg = shl;
  1087.   if (dlg != NULL) {
  1088.     XtSetMappedWhenManaged (shl, FALSE);
  1089.     XtAddEventHandler (shl, StructureNotifyMask, FALSE,
  1090.                        WindowResizeCallback, (XtPointer) w);
  1091.     n = 0;
  1092.     XtSetArg (wargs[n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1093.     XtSetArg (wargs[n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1094.     XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1095.     XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1096.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1097.     man = XmCreateMainWindow (dlg, (String) "", wargs, n);
  1098.     n = 0;
  1099.     XtSetArg (wargs[n], XmNwidth, (Dimension) (r.right - r.left)); n++;
  1100.     XtSetArg (wargs[n], XmNheight, (Dimension) (r.bottom - r.top)); n++;
  1101.     XtSetArg (wargs[n], XmNbuttonFontList, Nlm_XfontList); n++;
  1102.     XtSetArg (wargs[n], XmNlabelFontList, Nlm_XfontList); n++;
  1103.     XtSetArg (wargs[n], XmNtextFontList, Nlm_XfontList); n++;
  1104.     XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1105.     XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1106.     XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1107.     wptr = XmCreateBulletinBoard (man, (String) "", wargs, n);
  1108.  
  1109.     screen_num = DefaultScreen (Nlm_currentXDisplay);
  1110.     prt = Nlm_currentXGC;
  1111.     XtManageChild (man);
  1112.     XtManageChild (wptr);
  1113.     if (NLM_QUIET) {
  1114.       Nlm_currentXWindow = 0;
  1115.     } else {
  1116.       XtRealizeWidget (shl);
  1117.       Nlm_currentXWindow = XtWindow (shl);
  1118.     }
  1119.     atom = XmInternAtom (Nlm_currentXDisplay, "WM_DELETE_WINDOW", TRUE);
  1120.     if (atom != 0) {
  1121.       XmAddWMProtocolCallback (shl, atom, WindowCloseCallback, (XtPointer) w);
  1122.     }
  1123.   }
  1124.   if (temp [0] != '\0') {
  1125.     ttl = Nlm_StringSave (temp);
  1126.   }
  1127. #endif
  1128.   Nlm_currentWindowTool = wptr;
  1129.   r = screenBitBounds;
  1130.   Nlm_LoadRect (&drag, r.left + 4, r.top + 24, r.right - 4, r.bottom - 4);
  1131.   Nlm_LoadRect (&grow, r.left, r.top + 24, r.right, r.bottom);
  1132.   Nlm_LoadRect (&zoom, r.left + 4, r.top + 40, r.right - 4, r.bottom - 4);
  1133.   Nlm_LoadRect (&r, 0, 0, 0, 0);
  1134.  
  1135. #ifdef DCLAP
  1136. #ifdef WIN_MSWIN
  1137.   hsb = 6; vsb = 4;  /* dgg -- patch for mswin sizebar space */
  1138. #endif
  1139. #endif
  1140.  
  1141.   Nlm_LoadBoxData ((Nlm_BoX) w, pt, pt, pt, margin, margin,
  1142.                    margin + hsb, margin + vsb, spacing, spacing, 0, 0);
  1143.   Nlm_LoadWindowData (w, wptr, shl, prt, man, &drag, &grow, &zoom, close, NULL,
  1144.                       NULL, resize, NULL, NULL, NULL, TRUE, FALSE, ttl, NULL, NULL);
  1145. }
  1146.  
  1147. #ifdef WIN_MAC
  1148. static Nlm_WindoW Nlm_NextVisWindow (Nlm_WindoW w)
  1149.  
  1150. {
  1151.   WindowPeek  p;
  1152.   WindowPeek  q;
  1153.  
  1154.   if (w == Nlm_desktopWindow) {
  1155.     return Nlm_desktopWindow;
  1156.   } else {
  1157.     p = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1158.     while (p != NULL) {
  1159.       q = p->nextWindow;
  1160.       if (q != NULL) {
  1161.         if (q->visible != 0) {
  1162.           p = NULL;
  1163.         } else {
  1164.           p = q;
  1165.         }
  1166.       } else {
  1167.         p = q;
  1168.       }
  1169.     }
  1170.     return Nlm_FindWindowRec ((Nlm_WindowTool) q);
  1171.   }
  1172. }
  1173. #endif
  1174.  
  1175. static void Nlm_RemoveWindow (Nlm_GraphiC w, Nlm_Boolean savePort)
  1176.  
  1177. {
  1178.   Nlm_WindoW     nxt;
  1179.   Nlm_WindoW     p;
  1180.   Nlm_WindoW     q;
  1181. #ifdef WIN_MOTIF
  1182.   Nlm_ShellTool  shl;
  1183. #endif
  1184.  
  1185.   if ((Nlm_WindoW) w != Nlm_desktopWindow && (Nlm_WindoW) w != Nlm_systemWindow) {
  1186.     q = Nlm_desktopWindow;
  1187.     p = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  1188.     while (p != NULL && p != (Nlm_WindoW) w) {
  1189.       q = p;
  1190.       p = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) p);
  1191.     }
  1192.     if (p != NULL) {
  1193. #ifdef WIN_MAC
  1194.       HideWindow (Nlm_GetWindowPtr ((Nlm_WindoW) w));
  1195.       Nlm_Update ();
  1196. #endif
  1197. #ifdef WIN_MSWIN
  1198.       ShowWindow (Nlm_GetWindowPtr ((Nlm_WindoW) w), SW_HIDE);
  1199. #endif
  1200. #ifdef WIN_MOTIF
  1201.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1202.       if (NLM_QUIET) {
  1203.         if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1204.           XtUnmapWidget (shl);
  1205.         }
  1206.       } else {
  1207.         XtUnmapWidget (shl);
  1208.       }
  1209. #endif
  1210.       Nlm_SetWindowDying ((Nlm_WindoW) w, TRUE);
  1211.       nxt = (Nlm_WindoW) Nlm_GetNext (w);
  1212.       Nlm_SetNext ((Nlm_GraphiC) q, (Nlm_GraphiC) nxt);
  1213.       Nlm_SetNext (w, (Nlm_GraphiC) dyingWindow);
  1214.       dyingWindow = (Nlm_WindoW) w;
  1215.     }
  1216.   }
  1217.   Nlm_Update ();
  1218. }
  1219.  
  1220. static void Nlm_HideWindow (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1221.  
  1222. {
  1223.   Nlm_WindowTool  wptr;
  1224. #ifdef WIN_MOTIF
  1225.   Nlm_ShellTool   shl;
  1226. #endif
  1227.  
  1228.   wptr = Nlm_ParentWindowPtr (w);
  1229.   Nlm_SetVisible (w, FALSE);
  1230. #ifdef WIN_MAC
  1231.   HideWindow (wptr);
  1232.   Nlm_Update ();
  1233. #endif
  1234. #ifdef WIN_MSWIN
  1235.   ShowWindow (wptr, SW_HIDE);
  1236.   Nlm_Update ();
  1237. #endif
  1238. #ifdef WIN_MOTIF
  1239.   shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1240.   if (NLM_QUIET) {
  1241.     if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1242.       XtUnmapWidget (shl);
  1243.     }
  1244.   } else {
  1245.     XtUnmapWidget (shl);
  1246.   }
  1247.   Nlm_DoDeactivate (w, FALSE);
  1248.   Nlm_Update ();
  1249. #endif
  1250. }
  1251.  
  1252. /* Thanks to Mike Isaev for suggesting this solution to modal windows. */
  1253.  
  1254. static void Nlm_EnableOneWindow (Nlm_WindoW w, Nlm_Boolean onOffFlag)
  1255.  
  1256. {
  1257. #ifdef WIN_MSWIN
  1258.   Nlm_WindowTool  wptr;
  1259. #endif
  1260. #ifdef WIN_MOTIF
  1261.   Nlm_ShellTool   shl;
  1262. #endif
  1263.  
  1264.   if (w != NULL && w != Nlm_desktopWindow && w != Nlm_systemWindow) {
  1265. #ifdef WIN_MSWIN
  1266.     wptr = Nlm_GetWindowPtr (w);
  1267.     EnableWindow (wptr, onOffFlag);
  1268. #endif
  1269. #ifdef WIN_MOTIF
  1270.     shl = Nlm_GetWindowShell (w);
  1271.     XtVaSetValues (shl, XmNsensitive, onOffFlag, NULL);
  1272. #endif
  1273.   }
  1274. }
  1275.  
  1276. static void Nlm_EnableOtherWindows (Nlm_WindoW notThisWindow, Nlm_Boolean onOffFlag)
  1277.  
  1278. {
  1279.   Nlm_WindoW  w;
  1280.  
  1281.   w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  1282.   while (w != NULL && w != Nlm_systemWindow) {
  1283.     if (w != notThisWindow) {
  1284.       Nlm_EnableOneWindow (w, onOffFlag);
  1285.     }
  1286.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  1287.   }
  1288. }
  1289.  
  1290. static void Nlm_HideModal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1291.  
  1292. {
  1293.   Nlm_HideWindow (w, setFlag, savePort);
  1294.   Nlm_EnableOtherWindows ((Nlm_WindoW ) w, TRUE);
  1295. }
  1296.  
  1297. /* static -- dgg, make this public */
  1298. void Nlm_ResizeWindow (Nlm_GraphiC w, Nlm_Int2 dragHeight,
  1299.                               Nlm_Int2 scrollWidth, Nlm_Int2 minWidth,
  1300.                               Nlm_Int2 extraHeight)
  1301.  
  1302. {
  1303.   Nlm_BoxData     bdata;
  1304.   Nlm_Int4        free;
  1305.   Nlm_Int2        height;
  1306.   Nlm_Int4        leftpix;
  1307.   Nlm_PoinT       lpt;
  1308.   Nlm_Int2        menuHeight;
  1309.   Nlm_RecT        r;
  1310.   Nlm_Int4        rleft;
  1311.   Nlm_Int4        rtop;
  1312.   Nlm_Int4        toppix;
  1313.   Nlm_Int2        width;
  1314.   Nlm_WindowTool  wptr;
  1315. #ifdef WIN_MOTIF
  1316.   Nlm_ButtoN      b;
  1317.   Nlm_MainTool    man;
  1318.   Nlm_ShellTool   shl;
  1319.   Window          xtw;
  1320. #endif
  1321.  
  1322.   if (! Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1323. #ifdef WIN_MAC
  1324.     menuHeight = 21;
  1325.     TextFont (0);
  1326.     TextSize (0);
  1327. #endif
  1328. #ifdef WIN_MSWIN
  1329.     menuHeight = 0;
  1330. #endif
  1331. #ifdef WIN_MOTIF
  1332.     menuHeight = 0;
  1333. #endif
  1334.     Nlm_GetRect (w, &r);
  1335.     if (r.left < 0 || r.right < 0 || r.top < 0 || r.bottom < 0) {
  1336.       Nlm_GetBoxData ((Nlm_BoX) w, &bdata);
  1337.       lpt = bdata.limitPoint;
  1338.       if (r.right < 0) {
  1339.         width = lpt.x + scrollWidth + bdata.xMargin;
  1340.         if (width < minWidth) {
  1341.           width = minWidth;
  1342.         }
  1343.       } else {
  1344.         width = r.right;
  1345.       }
  1346.       if (r.bottom < 0) {
  1347.         height = lpt.y + scrollWidth + extraHeight + bdata.yMargin;
  1348.       } else {
  1349.         height = r.bottom + extraHeight;
  1350.       }
  1351.       if (r.left < 0) {
  1352.         free = screenBitBounds.right - width;
  1353.         rleft = (Nlm_Int4) r.left;
  1354.         leftpix = free * (-rleft) / 100;
  1355.         r.left = (Nlm_Int2) leftpix;
  1356.       }
  1357.       if (r.top < 0) {
  1358.         free = screenBitBounds.bottom - height - menuHeight - dragHeight;
  1359.         rtop = (Nlm_Int4) r.top;
  1360.         toppix = (free * (-rtop) / (Nlm_Int4) 100);
  1361.         r.top = (Nlm_Int2) (toppix + menuHeight + dragHeight);
  1362.       }
  1363.       r.right = r.left + width;
  1364.       r.bottom = r.top + height;
  1365.       Nlm_SetRect (w, &r);
  1366.       wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  1367. #ifdef WIN_MAC
  1368.       SizeWindow (wptr, width, height, FALSE);
  1369.       MoveWindow (wptr, r.left, r.top, FALSE);
  1370. #endif
  1371. #ifdef WIN_MSWIN
  1372.       MoveWindow (wptr, r.left, r.top, width, height, FALSE);
  1373. #endif
  1374. #ifdef WIN_MOTIF
  1375.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1376.       man = Nlm_GetWindowMain ((Nlm_WindoW) w);
  1377.       XtVaSetValues (shl,
  1378.                      XmNx, (Position) r.left,
  1379.                      XmNy, (Position) r.top, 
  1380.                      XmNwidth, (Dimension) width,
  1381.                      XmNheight, (Dimension) height, 
  1382.                      NULL);
  1383.       XtVaSetValues (man,
  1384.                      XmNwidth, (Dimension) width,
  1385.                      XmNheight, (Dimension) height, 
  1386.                      NULL);
  1387.       XtVaSetValues (wptr,
  1388.                      XmNwidth, (Dimension) width,
  1389.                      XmNheight, (Dimension) height, 
  1390.                      NULL);
  1391. #endif
  1392.     }
  1393. #ifdef WIN_MOTIF
  1394.     if (NLM_QUIET && (! Nlm_IsWindowDying ((Nlm_WindoW) w))) {
  1395.       b = Nlm_GetWindowDefaultButton ((Nlm_WindoW) w);
  1396.       if (b != NULL) {
  1397.         Nlm_MapDefaultButton ((Nlm_WindoW) w, b);
  1398.       }
  1399.       shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1400.       XtRealizeWidget (shl);
  1401.       man = Nlm_GetWindowMain ((Nlm_WindoW) w);
  1402.       xtw = XtWindow (man);
  1403.       if (xtw != 0) {
  1404.         XDefineCursor (Nlm_currentXDisplay, xtw, currentCursor);
  1405.       }
  1406.     }
  1407. #endif
  1408.   }
  1409. }
  1410.  
  1411. static void Nlm_ShowPlain (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1412.  
  1413. {
  1414.   Nlm_Int2        extra;
  1415.   Nlm_WindowTool  wptr;
  1416. #ifdef WIN_MOTIF
  1417.   Nlm_ShellTool   shl;
  1418. #endif
  1419.  
  1420.   wptr = Nlm_ParentWindowPtr (w);
  1421. #ifdef WIN_MAC
  1422.   Nlm_ResizeWindow (w, 0, 0, 0, 0);
  1423.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1424.   if (setFlag) {
  1425.     Nlm_SetVisible (w, TRUE);
  1426.     ShowWindow (wptr);
  1427.   }
  1428. #endif
  1429. #ifdef WIN_MSWIN
  1430.   extra = 2 * GetSystemMetrics (SM_CYBORDER);
  1431.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1432.     extra += GetSystemMetrics (SM_CYMENU);
  1433.   }
  1434.   Nlm_ResizeWindow (w, 0, 0, 0, extra);
  1435.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1436.   if (setFlag) {
  1437.     Nlm_SetVisible (w, TRUE);
  1438.     ShowWindow (wptr, SW_SHOW);
  1439.     UpdateWindow (wptr);
  1440.   }
  1441. #endif
  1442. #ifdef WIN_MOTIF
  1443.   extra = 0;
  1444.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1445.     extra += 31;
  1446.   }
  1447.   Nlm_ResizeWindow (w, 0, 0, 0, extra);
  1448.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1449.   if (setFlag) {
  1450.     Nlm_SetVisible (w, TRUE);
  1451.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1452.     XtMapWidget (shl);   
  1453.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1454.   }
  1455. #endif
  1456.   Nlm_Update ();
  1457. }
  1458.  
  1459. static void Nlm_ShowNormal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1460.  
  1461. {
  1462.   Nlm_Int2        extra;
  1463.   Nlm_Char        title [256];
  1464.   Nlm_WindowTool  wptr;
  1465. #ifdef WIN_MOTIF
  1466.   Nlm_ShellTool   shl;
  1467. #endif
  1468.  
  1469.   wptr = Nlm_ParentWindowPtr (w);
  1470.   Nlm_GetWindowTitle (w, 0, title, sizeof (title));
  1471. #ifdef WIN_MAC
  1472.   Nlm_ResizeWindow (w, 20, 0, Nlm_StringWidth (title) + 70, 0);
  1473.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1474.   if (setFlag) {
  1475.     Nlm_SetVisible (w, TRUE);
  1476.     ShowWindow (wptr);
  1477.   }
  1478. #endif
  1479. #ifdef WIN_MSWIN
  1480.   extra = GetSystemMetrics (SM_CYCAPTION) + 2 * GetSystemMetrics (SM_CYFRAME);
  1481.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1482.     extra += GetSystemMetrics (SM_CYMENU);
  1483.   }
  1484.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 80, extra);
  1485.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1486.   if (setFlag) {
  1487.     Nlm_SetVisible (w, TRUE);
  1488.     ShowWindow (wptr, SW_SHOW);
  1489.     UpdateWindow (wptr);
  1490.   }
  1491. #endif
  1492. #ifdef WIN_MOTIF
  1493.   extra = 0;
  1494.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1495.     extra += 31;
  1496.   }
  1497.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 65, extra);
  1498.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1499.   if (setFlag) {
  1500.     Nlm_SetVisible (w, TRUE);
  1501.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1502.     XtMapWidget (shl);   
  1503.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1504.   }
  1505. #endif
  1506.   Nlm_Update ();
  1507. }
  1508.  
  1509. static void Nlm_ShowModal (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1510.  
  1511. {
  1512.   Nlm_ShowNormal (w, setFlag, savePort);
  1513.   Nlm_EnableOtherWindows ((Nlm_WindoW ) w, FALSE);
  1514. }
  1515.  
  1516. static void Nlm_ShowDocument (Nlm_GraphiC w, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1517.  
  1518. {
  1519.   Nlm_Int2        extra;
  1520.   Nlm_Char        title [256];
  1521.   Nlm_WindowTool  wptr;
  1522. #ifdef WIN_MOTIF
  1523.   Nlm_ShellTool   shl;
  1524. #endif
  1525.  
  1526.   wptr = Nlm_ParentWindowPtr (w);
  1527.   Nlm_GetWindowTitle (w, 0, title, sizeof (title));
  1528. #ifdef WIN_MAC
  1529.   Nlm_ResizeWindow (w, 20, 16, Nlm_StringWidth (title) + 70, 0); 
  1530.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1531.   if (setFlag) {
  1532.     Nlm_SetVisible (w, TRUE);
  1533.     ShowWindow (wptr);
  1534.   }
  1535. #endif
  1536. #ifdef WIN_MSWIN
  1537.   extra = GetSystemMetrics (SM_CYCAPTION) + 2 * GetSystemMetrics (SM_CYBORDER);
  1538.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1539.     extra += GetSystemMetrics (SM_CYMENU);
  1540.   }
  1541.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 80, extra);
  1542.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1543.   if (setFlag) {
  1544.     Nlm_SetVisible (w, TRUE);
  1545.     ShowWindow (wptr, SW_SHOW);
  1546.     UpdateWindow (wptr);
  1547.   }
  1548. #endif
  1549. #ifdef WIN_MOTIF
  1550.   extra = 0;
  1551.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1552.     extra += 31;
  1553.   }
  1554.   Nlm_ResizeWindow (w, 0, 0, Nlm_StringWidth (title) + 65, extra);
  1555.   Nlm_SetNotYetShown ((Nlm_WindoW) w, FALSE);
  1556.   if (setFlag) {
  1557.     Nlm_SetVisible (w, TRUE);
  1558.     shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1559.     XtMapWidget (shl);   
  1560.     Nlm_DoActivate ((Nlm_GraphiC) w, FALSE);
  1561.   }
  1562. #endif
  1563.   Nlm_Update ();
  1564. }
  1565.  
  1566. extern void Nlm_RealizeWindow (Nlm_WindoW w)
  1567.  
  1568. {
  1569.   if (w != NULL) {
  1570.     Nlm_DoShow ((Nlm_GraphiC) w, FALSE, TRUE);
  1571.   }
  1572. }
  1573.  
  1574. extern Nlm_WindoW Nlm_WhichWindow (Nlm_PoinT mouseLoc)
  1575.  
  1576. {
  1577. #ifdef WIN_MAC
  1578.   Nlm_PoinT       point;
  1579.   Nlm_PointTool   ptool;
  1580.   Nlm_Int2        windowLoc;
  1581.   Nlm_WindowTool  wptr;
  1582.  
  1583.   point = mouseLoc;
  1584.   Nlm_LocalToGlobal (&point);
  1585.   Nlm_PoinTToPointTool (point, &ptool);
  1586.   windowLoc = FindWindow (ptool, &wptr);
  1587.   return Nlm_FindWindowRec (wptr);
  1588. #endif
  1589. #ifdef WIN_MSWIN
  1590.   Nlm_PoinT       point;
  1591.   Nlm_PointTool   ptool;
  1592.   Nlm_WindoW      rsult;
  1593.   Nlm_WindowTool  wptr;
  1594.  
  1595.   rsult = NULL;
  1596.   point = mouseLoc;
  1597.   Nlm_LocalToGlobal (&point);
  1598.   Nlm_PoinTToPointTool (point, &ptool);
  1599.   wptr = WindowFromPoint (ptool);
  1600.   if (wptr != NULL) {
  1601.     rsult = (Nlm_WindoW) GetProp (wptr, (LPSTR) "Nlm_VibrantProp");
  1602.   }
  1603.   return rsult;
  1604. #endif
  1605. #ifdef WIN_MOTIF
  1606.   return NULL;
  1607. #endif
  1608. }
  1609.  
  1610. extern Nlm_Boolean Nlm_InWindow (Nlm_PoinT mouseLoc)
  1611.  
  1612. {
  1613.   return (Nlm_Boolean) (Nlm_WhichWindow (mouseLoc) != Nlm_desktopWindow);
  1614. }
  1615.  
  1616. extern Nlm_WindoW Nlm_FrontWindow ()
  1617.  
  1618. {
  1619. #ifdef WIN_MAC
  1620.   return (Nlm_FindWindowRec (FrontWindow ()));
  1621. #endif
  1622. #ifdef WIN_MSWIN
  1623.   return (Nlm_FindWindowRec (Nlm_currentHWnd));
  1624. #endif
  1625. #ifdef WIN_MOTIF
  1626.   return NULL;
  1627. #endif
  1628. }
  1629.  
  1630. extern Nlm_Boolean Nlm_InFront (Nlm_WindoW w)
  1631.  
  1632. {
  1633. #ifdef WIN_MAC
  1634.   return (w == Nlm_FrontWindow ());
  1635. #endif
  1636. #ifdef WIN_MSWIN
  1637.   return FALSE;
  1638. #endif
  1639. #ifdef WIN_MOTIF
  1640.   return FALSE;
  1641. #endif
  1642. }
  1643.  
  1644. extern void Nlm_UseWindow (Nlm_WindoW w)
  1645.  
  1646. {
  1647.   Nlm_WindowTool  wptr;
  1648. #ifdef WIN_MOTIF
  1649.   Nlm_ShellTool   shl;
  1650. #endif
  1651.  
  1652.   if (w != NULL && w != Nlm_desktopWindow) {
  1653.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1654.     if (wptr != NULL && (! Nlm_IsWindowDying (w))) {
  1655. #ifdef WIN_MAC
  1656.       SetPort (wptr);
  1657.       Nlm_SetUpdateRegion (wptr);
  1658.       Nlm_ResetDrawingTools ();
  1659. #endif
  1660. #ifdef WIN_MSWIN
  1661.       Nlm_currentHDC = Nlm_GetWindowPort (w);
  1662.       Nlm_currentHWnd = wptr;
  1663. #endif
  1664. #ifdef WIN_MOTIF
  1665.       shl = Nlm_GetWindowShell (w);
  1666.       Nlm_currentXWindow = XtWindow (shl);
  1667.       Nlm_currentXGC = Nlm_GetWindowPort (w);
  1668. #endif
  1669.       Nlm_currentWindowTool = wptr;
  1670.     }
  1671.   }
  1672. }
  1673.  
  1674. extern Nlm_WindoW Nlm_CurrentWindow ()
  1675.  
  1676. {
  1677.   Nlm_WindoW  rsult;
  1678.  
  1679.   rsult = Nlm_FindWindowRec (Nlm_currentWindowTool);
  1680.   return rsult;
  1681. }
  1682.  
  1683. extern Nlm_Boolean Nlm_UsingWindow (Nlm_WindoW w)
  1684.  
  1685. {
  1686.   return (Nlm_Boolean) (w == Nlm_CurrentWindow ());
  1687. }
  1688.  
  1689. extern Nlm_WindoW Nlm_ActiveWindow ()
  1690.  
  1691. {
  1692.   Nlm_WindoW      rsult;
  1693.   Nlm_WindowTool  wptr;
  1694.  
  1695.   rsult = NULL;
  1696. #ifdef WIN_MAC
  1697.   rsult = Nlm_theWindow;
  1698. #endif
  1699. #ifdef WIN_MSWIN
  1700.   wptr = GetActiveWindow ();
  1701.   if (wptr != NULL) {
  1702.     rsult = (Nlm_WindoW) GetProp (wptr, (LPSTR) "Nlm_VibrantProp");
  1703.   }
  1704. #endif
  1705. #ifdef WIN_MOTIF
  1706. #endif
  1707.   return rsult;
  1708. }
  1709.  
  1710. #ifdef WIN_MAC
  1711. static Nlm_WindoW Nlm_PrevVisWindow (Nlm_WindoW w)
  1712.  
  1713. {
  1714.   WindowPeek  p;
  1715.   WindowPeek  q;
  1716.   WindowPeek  t;
  1717.  
  1718.   if (frontWindow == Nlm_desktopWindow) {
  1719.     return Nlm_desktopWindow;
  1720.   } else if (frontWindow == w) {
  1721.     return frontWindow;
  1722.   } else {
  1723.     p = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) frontWindow);
  1724.     q = p;
  1725.     t = (WindowPeek) Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1726.     while (p != NULL) {
  1727.       if (p == t) {
  1728.         p = NULL;
  1729.       } else if (p->visible != 0) {
  1730.         q = p;
  1731.         p = p->nextWindow;
  1732.       } else {
  1733.         p = p->nextWindow;
  1734.       }
  1735.     }
  1736.     return (Nlm_FindWindowRec ((Nlm_WindowTool) q));
  1737.   }
  1738. }
  1739. #endif
  1740.  
  1741. static void Nlm_SelectWindow (Nlm_GraphiC w, Nlm_Boolean savePort)
  1742.  
  1743. {
  1744.   Nlm_WindowTool  wptr;
  1745. #ifdef WIN_MOTIF
  1746.   Nlm_ShellTool   shl;
  1747. #endif
  1748.  
  1749.   if (w != NULL && (Nlm_WindoW) w != Nlm_desktopWindow) {
  1750.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1751.     if (wptr != NULL && (! Nlm_IsWindowDying ((Nlm_WindoW) w))) {
  1752. #ifdef WIN_MAC
  1753.       SelectWindow (wptr);
  1754.       SetPort (wptr);
  1755.       Nlm_SetUpdateRegion (wptr);
  1756.       Nlm_ResetDrawingTools ();
  1757. #endif
  1758. #ifdef WIN_MSWIN
  1759.       BringWindowToTop (wptr);
  1760. /* M.I */
  1761.       if( IsIconic( wptr ) )
  1762.         ShowWindow( wptr, SW_RESTORE );  /* de-Iconize window */
  1763. /* M.I */
  1764.       Nlm_currentHDC = Nlm_GetWindowPort ((Nlm_WindoW) w);
  1765.       Nlm_currentHWnd = wptr;
  1766. #endif
  1767. #ifdef WIN_MOTIF
  1768.       if (Nlm_WindowHasBeenShown ((Nlm_WindoW) w)) {
  1769.         if (Nlm_currentXDisplay != NULL) {
  1770.           shl = Nlm_GetWindowShell ((Nlm_WindoW) w);
  1771.           XMapRaised (Nlm_currentXDisplay, XtWindow (shl));
  1772.         }
  1773.       }
  1774. #endif
  1775.       Nlm_currentWindowTool = wptr;
  1776.       Nlm_Update ();
  1777.     }
  1778.   }
  1779. }
  1780.  
  1781. extern void Nlm_EraseWindow (Nlm_WindoW w)
  1782.  
  1783. {
  1784. #ifdef WIN_MAC
  1785.   Nlm_RecT        r;
  1786.   Nlm_PortTool    temp;
  1787.   Nlm_WindowTool  wptr;
  1788.  
  1789.   if (w != NULL) {
  1790.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  1791.     GetPort (&temp);
  1792.     SetPort (wptr);
  1793.     Nlm_ResetDrawingTools ();
  1794.     Nlm_currentWindowTool = wptr;
  1795.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1796.     Nlm_EraseRect (&r);
  1797.     SetPort (temp);
  1798.     Nlm_currentWindowTool = temp;
  1799.     Nlm_Update ();
  1800.   }
  1801. #endif
  1802. #ifdef WIN_MSWIN
  1803. #endif
  1804. #ifdef WIN_MOTIF
  1805. #endif
  1806. }
  1807.  
  1808. #ifdef WIN_MAC
  1809. static Nlm_Boolean Nlm_DragClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1810.  
  1811. {
  1812.   Nlm_PointTool   ptool;
  1813.   Nlm_RecT        r;
  1814.   Nlm_RectTool    rtool;
  1815.   Nlm_Boolean     rsult;
  1816.   Nlm_Int2        windowLoc;
  1817.   Nlm_WindowData  wdata;
  1818.   Nlm_WindowTool  wptr;
  1819.  
  1820.   rsult = FALSE;
  1821.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1822.   windowLoc = FindWindow (ptool, &wptr);
  1823.   if (windowLoc == inDrag) {
  1824.     Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  1825.     Nlm_RecTToRectTool (&(wdata.dragArea), &rtool);
  1826.     DragWindow (wptr, ptool, &rtool);
  1827.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1828.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  1829.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  1830.     Nlm_SetRect (w, &r);
  1831.     rsult = TRUE;
  1832.   }
  1833.   return rsult;
  1834. }
  1835.  
  1836. static void Nlm_UpdateScrollBar (Nlm_GraphiC w)
  1837.  
  1838. {
  1839.   Nlm_RecT        barArea;
  1840.   Nlm_WindowTool  wptr;
  1841.  
  1842.   wptr = Nlm_ParentWindowPtr (w);
  1843.   Nlm_RectToolToRecT (&(wptr->portRect), &barArea);
  1844.   barArea.left = barArea.right - 16;
  1845.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1846.     barArea.top = barArea.top + 21;
  1847.   }
  1848.   Nlm_InvalRect (&barArea);
  1849.   Nlm_RectToolToRecT (&(wptr->portRect), &barArea);
  1850.   barArea.top = barArea.bottom - 16;
  1851.   Nlm_InvalRect (&barArea);
  1852. }
  1853.  
  1854. static Nlm_Boolean Nlm_GrowClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1855.  
  1856. {
  1857.   Nlm_Int2         ht;
  1858.   Nlm_Int4         newSize;
  1859.   Nlm_PointTool    ptool;
  1860.   Nlm_RecT         r;
  1861.   Nlm_WndActnProc  resize;
  1862.   Nlm_RectTool     rtool;
  1863.   Nlm_Boolean      rsult;
  1864.   Nlm_Int2         wd;
  1865.   Nlm_WindowData   wdata;
  1866.   Nlm_Int2         windowLoc;
  1867.   Nlm_WindowTool   wptr;
  1868.  
  1869.   rsult = FALSE;
  1870.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1871.   windowLoc = FindWindow (ptool, &wptr);
  1872.   if (windowLoc == inGrow) {
  1873.     Nlm_LoadRect (&r, -32768, -32768, 32767, 32767);
  1874.     Nlm_RecTToRectTool (&r, &rtool);
  1875.     ClipRect (&rtool);
  1876.     Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  1877.     Nlm_RecTToRectTool (&(wdata.growArea), &rtool);
  1878.     newSize = GrowWindow (wptr, ptool, &rtool);
  1879.     wd = LoWord (newSize);
  1880.     ht = HiWord (newSize);
  1881.  /* dgg -- bug fix: simple click on grow box caused it to resize to 0 -- 
  1882.     should check here for 0 == no change.  Also make minsize bigger. 
  1883.  */
  1884.     if (! newSize) {
  1885.       ClipRect (&(wptr->portRect));
  1886.       return rsult;
  1887.     }
  1888.     if (wd < 50) {
  1889.       wd = 50;
  1890.     }
  1891.     if (ht < 32) {
  1892.       ht = 32;
  1893.     }
  1894.     Nlm_UpdateScrollBar (w);
  1895.     SizeWindow (wptr, wd, ht, TRUE);
  1896.     Nlm_UpdateScrollBar (w);
  1897.     wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  1898.     Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1899.     ClipRect (&(wptr->portRect));
  1900.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  1901.     Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  1902.     Nlm_SetRect (w, &r);
  1903.     resize = wdata.resize;
  1904.     if (resize != NULL) {
  1905.       resize ((Nlm_WindoW) w);
  1906.     }
  1907.     rsult = TRUE;
  1908.   }
  1909.   return rsult;
  1910. }
  1911.  
  1912. static void Nlm_DrawGrowIcon (Nlm_GraphiC w)
  1913.  
  1914. {
  1915.   Nlm_RecT        r;
  1916.   Nlm_RectTool    rtool;
  1917.   PenState        state;
  1918.   Nlm_PortTool    temp;
  1919.   Nlm_WindowTool  wptr;
  1920.  
  1921.   GetPort (&temp);
  1922.   GetPenState (&state);
  1923.   wptr = Nlm_ParentWindowPtr (w);
  1924.   Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1925.   if (Nlm_GetWindowMenuBar ((Nlm_WindoW) w) != NULL) {
  1926.     Nlm_RecTToRectTool (&r, &rtool);
  1927.     ClipRect (&rtool);
  1928.     MoveTo (r.right - 16, 20);
  1929.     LineTo (r.right, 20);
  1930.     r.top = r.top + 21;
  1931.   }
  1932. #ifdef DCLAP
  1933.     /* clip out the scrollbar guides */
  1934.   r.left = r.right - 15;
  1935.   r.top = r.bottom - 15;
  1936. #endif
  1937.   Nlm_RecTToRectTool (&r, &rtool);
  1938.   ClipRect (&rtool);
  1939.   DrawGrowIcon (wptr);
  1940.   r.top = wptr->portRect.top;
  1941. #ifdef DCLAP
  1942.   /* dgg- this cliprect is the culprit for preventing scrollbar updates by subviews */
  1943.   /* try clipping a region that excludes just the growicon?? */
  1944.   r.left = wptr->portRect.left;
  1945. #else
  1946.   r.right = r.right - 16;
  1947.   r.bottom = r.bottom - 16;
  1948. #endif
  1949.   Nlm_RecTToRectTool (&r, &rtool);
  1950.   ClipRect (&rtool);
  1951.   SetPort (temp);
  1952.   Nlm_currentWindowTool = temp;
  1953.   Nlm_SetUpdateRegion (temp);
  1954.   SetPenState (&state);
  1955. }
  1956.  
  1957. static Nlm_Boolean Nlm_ZoomClick (Nlm_GraphiC w, Nlm_PoinT pt)
  1958.  
  1959. {
  1960.   Nlm_PointTool    ptool;
  1961.   Nlm_RecT         r;
  1962.   Nlm_WndActnProc  resize;
  1963.   Nlm_Boolean      rsult;
  1964.   Nlm_RectTool     rtool;
  1965.   Nlm_WindowData   wdata;
  1966.   Nlm_Int2         windowLoc;
  1967.   WindowPeek       wpeek;
  1968.   Nlm_WindowTool   wptr;
  1969.   WStateData       **wshdl;
  1970.   WStateData       *wsptr;
  1971.  
  1972.   rsult = FALSE;
  1973.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  1974.   windowLoc = FindWindow (ptool, &wptr);
  1975.   if (windowLoc == inZoomIn || windowLoc == inZoomOut) {
  1976.     if (TrackBox (wptr, ptool, windowLoc)) {
  1977.       wpeek = (WindowPeek) wptr;
  1978.       wshdl = (WStateData**) wpeek->dataHandle;
  1979.       wsptr = *wshdl;
  1980.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  1981.       r = wdata.zoomArea;
  1982.       Nlm_RecTToRectTool (&r, &(wsptr->stdState));
  1983.       Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1984.       ClipRect (&(wptr->portRect));
  1985.       Nlm_EraseRect (&r);
  1986.       ZoomWindow (wptr, windowLoc, FALSE);
  1987.       Nlm_UpdateScrollBar (w);
  1988.       wptr = Nlm_GetWindowPtr ((Nlm_WindoW) w);
  1989.       Nlm_RectToolToRecT (&(wptr->portRect), &r);
  1990.       ClipRect (&(wptr->portRect));
  1991.       Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.left));
  1992.       Nlm_LocalToGlobal ((Nlm_PointPtr) &(r.right));
  1993.       Nlm_SetRect (w, &r);
  1994.       resize = wdata.resize;
  1995.       if (resize != NULL) {
  1996.         resize ((Nlm_WindoW) w);
  1997.       }
  1998.     }
  1999.     rsult = TRUE;
  2000.   }
  2001.   return rsult;
  2002. }
  2003.  
  2004. static Nlm_Boolean Nlm_CloseClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2005.  
  2006. {
  2007.   Nlm_WndActnProc  cls;
  2008.   Nlm_PointTool    ptool;
  2009.   Nlm_Boolean      rsult;
  2010.   Nlm_WindowData   wdata;
  2011.   Nlm_Int2         windowLoc;
  2012.   Nlm_WindowTool   wptr;
  2013.  
  2014.   rsult = FALSE;
  2015.   Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  2016.   windowLoc = FindWindow (ptool, &wptr);
  2017.   if (windowLoc == inGoAway) {
  2018.     if (TrackGoAway (wptr, ptool)) {
  2019.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2020.       cls = wdata.close;
  2021.       if (cls != NULL) {
  2022.         cls ((Nlm_WindoW) w);
  2023.       }
  2024.     }
  2025.     rsult = TRUE;
  2026.   }
  2027.   return rsult;
  2028. }
  2029.  
  2030. typedef struct revItem {
  2031.   Nlm_GraphiC          graphic;
  2032.   struct revItem  PNTR next;
  2033. } Nlm_RevItem, PNTR Nlm_RevPtr;
  2034.  
  2035. static Nlm_Boolean Nlm_ContentClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2036.  
  2037. {
  2038.   Nlm_GraphiC    g;
  2039.   Nlm_MenuBaR    mb;
  2040.   Nlm_GraphiC    n;
  2041.   Nlm_RevPtr     next;
  2042.   Nlm_Boolean    notInside;
  2043.   Nlm_PointTool  ptool;
  2044.   Nlm_RevPtr     thisitem;
  2045.   Nlm_RevPtr     top;
  2046.  
  2047.   Nlm_localMouse = Nlm_globalMouse;
  2048.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2049.   g = Nlm_GetChild (w);
  2050.   notInside = TRUE;
  2051.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2052.   if (mb != NULL) {
  2053.     if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2054.         Nlm_DoClick ((Nlm_GraphiC) mb, Nlm_localMouse)) {
  2055.       notInside = FALSE;
  2056.     }
  2057.   }
  2058.   /*
  2059.   while (g != NULL && notInside) {
  2060.     n = Nlm_GetNext (g);
  2061.     if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, Nlm_localMouse)) {
  2062.       notInside = FALSE;
  2063.     }
  2064.     g = n;
  2065.   }
  2066.   */
  2067.   if (g != NULL && notInside) {
  2068.     top = NULL;
  2069.     while (g != NULL) {
  2070.       thisitem = (Nlm_RevPtr) Nlm_MemNew (sizeof (Nlm_RevItem));
  2071.       if (thisitem != NULL) {
  2072.         thisitem->graphic = g;
  2073.         thisitem->next = top;
  2074.         top = thisitem;
  2075.       }
  2076.       g = Nlm_GetNext (g);
  2077.     }
  2078.     thisitem = top;
  2079.     while (thisitem != NULL && notInside) {
  2080.       next = thisitem->next;
  2081.       g = thisitem->graphic;
  2082.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, Nlm_localMouse)) {
  2083.         notInside = FALSE;
  2084.       }
  2085.       thisitem = next;
  2086.     }
  2087.     thisitem = top;
  2088.     while (thisitem != NULL) {
  2089.       next = thisitem->next;
  2090.       Nlm_MemFree (thisitem);
  2091.       thisitem = next;
  2092.     }
  2093.   }
  2094.   if (notInside) {
  2095.     GetMouse (&ptool);
  2096.     Nlm_PointToolToPoinT (ptool, &Nlm_localMouse);
  2097.     if ((Nlm_WindoW) w != Nlm_WhichWindow (Nlm_localMouse)) {
  2098.       notInside = FALSE;
  2099.     }
  2100.   }
  2101.   return (! notInside);
  2102. }
  2103.  
  2104. static Nlm_Boolean Nlm_CommonClick (Nlm_GraphiC w, Nlm_PoinT pt,
  2105.                                     Nlm_Boolean close, Nlm_Boolean drag,
  2106.                                     Nlm_Boolean grow, Nlm_Boolean zoom)
  2107.  
  2108. {
  2109.   Nlm_Boolean     rsult;
  2110.   PenState        state;
  2111.   Nlm_PortTool    temp;
  2112.   Nlm_WindowTool  wptr;
  2113.  
  2114.   rsult = FALSE;
  2115.   if (chosenWindow == (Nlm_WindoW) w) {
  2116.     wptr = Nlm_ParentWindowPtr (w);
  2117.     GetPort (&temp);
  2118.     GetPenState (&state);
  2119.     SetPort (wptr);
  2120.     Nlm_currentWindowTool = wptr;
  2121.     Nlm_SetUpdateRegion (wptr);
  2122.     Nlm_ResetDrawingTools ();
  2123.     if ((close && Nlm_CloseClick (w, pt)) ||
  2124.        (drag && Nlm_DragClick (w, pt)) ||
  2125.        (grow && Nlm_GrowClick (w, pt)) ||
  2126.        (zoom && Nlm_ZoomClick (w, pt))) {
  2127.     } else {
  2128.       rsult = Nlm_ContentClick (w, pt);
  2129.     }
  2130.     SetPort (temp);
  2131.     Nlm_currentWindowTool = temp;
  2132.     Nlm_SetUpdateRegion (temp);
  2133.     SetPenState (&state);
  2134.   } else if (chosenWindow != NULL) {
  2135.     Nlm_DoSelect ((Nlm_GraphiC) chosenWindow, TRUE);
  2136.   }
  2137.   return rsult;
  2138. }
  2139.  
  2140. static Nlm_Boolean Nlm_DocumentClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2141.  
  2142. {
  2143.   return Nlm_CommonClick (w, pt, TRUE, TRUE, TRUE, TRUE);
  2144. }
  2145.  
  2146. static Nlm_Boolean Nlm_DialogClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2147.  
  2148. {
  2149.   return Nlm_CommonClick (w, pt, TRUE, TRUE, FALSE, FALSE);
  2150. }
  2151.  
  2152. static Nlm_Boolean Nlm_FrozenClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2153.  
  2154. {
  2155.   return Nlm_CommonClick (w, pt, TRUE, FALSE, FALSE, FALSE);
  2156. }
  2157.  
  2158. static Nlm_Boolean Nlm_PlainClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2159.  
  2160. {
  2161.   return Nlm_CommonClick (w, pt, FALSE, FALSE, FALSE, FALSE);
  2162. }
  2163.  
  2164. static Nlm_Boolean Nlm_ModalClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2165.  
  2166. {
  2167.   Nlm_WndActnProc  cls;
  2168.   Nlm_Boolean      rsult;
  2169.   PenState         state;
  2170.   Nlm_PortTool     temp;
  2171.   Nlm_WindowData   wdata;
  2172.   Nlm_WindowTool   wptr;
  2173.  
  2174.   rsult = FALSE;
  2175.   if (chosenWindow == (Nlm_WindoW) w) {
  2176.     rsult = Nlm_CommonClick (w, pt, FALSE, FALSE, FALSE, FALSE);
  2177.     if (! rsult) {
  2178.       Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2179.       cls = wdata.close;
  2180.       if (cls != NULL) {
  2181.         wptr = Nlm_ParentWindowPtr (w);
  2182.         GetPort (&temp);
  2183.         GetPenState (&state);
  2184.         SetPort (wptr);
  2185.         Nlm_currentWindowTool = wptr;
  2186.         Nlm_SetUpdateRegion (wptr);
  2187.         Nlm_ResetDrawingTools ();
  2188.         cls ((Nlm_WindoW) w);
  2189.         SetPort (temp);
  2190.         Nlm_currentWindowTool = temp;
  2191.         Nlm_SetUpdateRegion (temp);
  2192.         SetPenState (&state);
  2193.       }
  2194.     }
  2195.   } else {
  2196.     Nlm_Beep ();
  2197.   }
  2198.   return rsult;
  2199. }
  2200.  
  2201. static Nlm_Boolean Nlm_FloatingClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2202.  
  2203. {
  2204.   Nlm_WindoW  nw;
  2205.  
  2206.   if (chosenWindow == (Nlm_WindoW) w) {
  2207.     Nlm_CommonClick (w, Nlm_globalMouse, TRUE, TRUE, FALSE, FALSE);
  2208.   } else {
  2209.     nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2210.     Nlm_DoClick ((Nlm_GraphiC) nw, Nlm_globalMouse);
  2211.   }
  2212.   return TRUE;
  2213. }
  2214.  
  2215. static Nlm_Boolean Nlm_SystemClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2216.  
  2217. {
  2218.   Nlm_WindowTool  wptr;
  2219.  
  2220.   if (chosenWindow == (Nlm_WindoW) w) {
  2221.     wptr = Nlm_ParentWindowPtr (w);
  2222.     SystemClick (&Nlm_currentEvent, wptr);
  2223.   } else {
  2224.     Nlm_DoSelect ((Nlm_GraphiC) chosenWindow, TRUE);
  2225.   }
  2226.   return TRUE;
  2227. }
  2228.  
  2229. static Nlm_Boolean Nlm_DesktopClick (Nlm_GraphiC w, Nlm_PoinT pt)
  2230.  
  2231. {
  2232.   Nlm_MenuBaR  mb;
  2233.  
  2234.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2235.   Nlm_localMouse = Nlm_globalMouse;
  2236.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2237.   (void) (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2238.           Nlm_DoClick ((Nlm_GraphiC) mb, Nlm_localMouse));
  2239.   return TRUE;
  2240. }
  2241. #endif
  2242.  
  2243. static void Nlm_NormalSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2244.  
  2245. {
  2246. #ifdef WIN_MAC
  2247.   if ((! Nlm_DragClick (w, Nlm_localMouse)) || (! Nlm_cmmdKey)) {
  2248.     Nlm_SelectWindow (w, FALSE);
  2249.   }
  2250. #endif
  2251. #ifdef WIN_MSWIN
  2252.   Nlm_SelectWindow (w, FALSE);
  2253. #endif
  2254. #ifdef WIN_MOTIF
  2255.   Nlm_SelectWindow (w, FALSE);
  2256. #endif
  2257. }
  2258.  
  2259. static void Nlm_PlainSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2260.  
  2261. {
  2262. #ifdef WIN_MAC
  2263.   Nlm_SelectWindow (w, FALSE);
  2264. #endif
  2265. #ifdef WIN_MSWIN
  2266.   Nlm_SelectWindow (w, FALSE);
  2267. #endif
  2268. #ifdef WIN_MOTIF
  2269.   Nlm_SelectWindow (w, FALSE);
  2270. #endif
  2271. }
  2272.  
  2273. static void Nlm_FloatingSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2274.  
  2275. {
  2276. #ifdef WIN_MAC
  2277.   PenState        state;
  2278.   Nlm_PortTool    temp;
  2279.   Nlm_WindowTool  wptr;
  2280.  
  2281.   wptr = Nlm_ParentWindowPtr (w);
  2282.   GetPort (&temp);
  2283.   GetPenState (&state);
  2284.   SetPort (wptr);
  2285.   Nlm_currentWindowTool = wptr;
  2286.   Nlm_SetUpdateRegion (wptr);
  2287.   Nlm_ResetDrawingTools ();
  2288.   Nlm_localMouse = Nlm_globalMouse;
  2289.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2290.   if (Nlm_DragClick (w, Nlm_globalMouse) || Nlm_CloseClick (w, Nlm_globalMouse)) {
  2291.   } else {
  2292.     Nlm_ContentClick (w, Nlm_globalMouse);
  2293.   }
  2294.   SetPort (temp);
  2295.   Nlm_currentWindowTool = temp;
  2296.   Nlm_SetUpdateRegion (temp);
  2297.   SetPenState (&state);
  2298.   Nlm_localMouse = Nlm_globalMouse;
  2299.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2300. #endif
  2301. #ifdef WIN_MSWIN
  2302.   Nlm_SelectWindow (w, FALSE);
  2303. #endif
  2304. #ifdef WIN_MOTIF
  2305.   Nlm_SelectWindow (w, FALSE);
  2306. #endif
  2307. }
  2308.  
  2309. static void Nlm_DesktopSelect (Nlm_GraphiC w, Nlm_Boolean savePort)
  2310.  
  2311. {
  2312. #ifdef WIN_MAC
  2313.   PenState      state;
  2314.   Nlm_PortTool  temp;
  2315.  
  2316.   GetPort (&temp);
  2317.   GetPenState (&state);
  2318.   PenNormal ();
  2319.   Nlm_DesktopClick (w, Nlm_globalMouse);
  2320.   SetPort (temp);
  2321.   Nlm_currentWindowTool = temp;
  2322.   Nlm_SetUpdateRegion (temp);
  2323.   SetPenState (&state);
  2324. #endif
  2325. }
  2326.  
  2327. #ifdef WIN_MAC
  2328. static Nlm_Boolean Nlm_DesktopKey (Nlm_GraphiC w, Nlm_Char ch)
  2329.  
  2330. {
  2331.   Nlm_MenuBaR  mb;
  2332.  
  2333.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2334.   Nlm_localMouse = Nlm_globalMouse;
  2335.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2336.   if (Nlm_currentKey != '\0') {
  2337.     (void) (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2338.             Nlm_DoKey ((Nlm_GraphiC) mb, ch));
  2339.   }
  2340.   return TRUE;
  2341. }
  2342.  
  2343. static Nlm_Boolean Nlm_NormalKey (Nlm_GraphiC w, Nlm_Char ch)
  2344.  
  2345. {
  2346.   Nlm_GraphiC     g;
  2347.   Nlm_MenuBaR     mb;
  2348.   Nlm_GraphiC     n;
  2349.   Nlm_Boolean     notInside;
  2350.   PenState        state;
  2351.   Nlm_PortTool    temp;
  2352.   Nlm_WindowTool  wptr;
  2353.  
  2354.   wptr = Nlm_ParentWindowPtr (w);
  2355.   GetPort (&temp);
  2356.   GetPenState (&state);
  2357.   SetPort (wptr);
  2358.   Nlm_currentWindowTool = wptr;
  2359.   Nlm_SetUpdateRegion (wptr);
  2360.   Nlm_ResetDrawingTools ();
  2361.   Nlm_localMouse = Nlm_globalMouse;
  2362.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2363.   if (Nlm_currentKey != '\0') {
  2364.     g = Nlm_GetChild (w);
  2365.     notInside = TRUE;
  2366.     mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2367.     if (mb != NULL) {
  2368.       if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2369.           Nlm_DoKey ((Nlm_GraphiC) mb, ch)) {
  2370.         notInside = FALSE;
  2371.       }
  2372.     }
  2373.     while (g != NULL && notInside) {
  2374.       n = Nlm_GetNext (g);
  2375.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoKey (g, ch)) {
  2376.         notInside = FALSE;
  2377.       }
  2378.       g = n;
  2379.     }
  2380.     if (notInside && Nlm_cmmdKey) {
  2381.       Nlm_DesktopKey ((Nlm_GraphiC) Nlm_desktopWindow, ch);
  2382.     }
  2383.   }
  2384.   SetPort (temp);
  2385.   Nlm_currentWindowTool = temp;
  2386.   Nlm_SetUpdateRegion (temp);
  2387.   SetPenState (&state);
  2388.   return TRUE;
  2389. }
  2390.  
  2391. static Nlm_Boolean Nlm_FloatingKey (Nlm_GraphiC w, Nlm_Char ch)
  2392.  
  2393. {
  2394.   Nlm_GraphiC     g;
  2395.   Nlm_MenuBaR     mb;
  2396.   Nlm_GraphiC     n;
  2397.   Nlm_WindoW      nw;
  2398.   Nlm_Boolean     notInside;
  2399.   PenState        state;
  2400.   Nlm_PortTool    temp;
  2401.   Nlm_WindowTool  wptr;
  2402.  
  2403.   wptr = Nlm_ParentWindowPtr (w);
  2404.   GetPort (&temp);
  2405.   GetPenState (&state);
  2406.   SetPort (wptr);
  2407.   Nlm_currentWindowTool = wptr;
  2408.   Nlm_SetUpdateRegion (wptr);
  2409.   Nlm_ResetDrawingTools ();
  2410.   Nlm_localMouse = Nlm_globalMouse;
  2411.   Nlm_GlobalToLocal (&Nlm_localMouse);
  2412.   if (Nlm_currentKey != '\0') {
  2413.     g = Nlm_GetChild (w);
  2414.     notInside = TRUE;
  2415.     mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2416.     if (mb != NULL) {
  2417.       if (Nlm_GetEnabled ((Nlm_GraphiC) mb) && Nlm_GetVisible ((Nlm_GraphiC) mb) &&
  2418.           Nlm_DoKey ((Nlm_GraphiC) mb, ch)) {
  2419.         notInside = FALSE;
  2420.       }
  2421.     }
  2422.     while (g != NULL && notInside) {
  2423.       n = Nlm_GetNext (g);
  2424.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoKey (g, ch)) {
  2425.         notInside = FALSE;
  2426.       }
  2427.       g = n;
  2428.     }
  2429.     if (notInside) {
  2430.       nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2431.       Nlm_DoKey ((Nlm_GraphiC) nw, ch);
  2432.     }
  2433.   }
  2434.   SetPort (temp);
  2435.   Nlm_currentWindowTool = temp;
  2436.   Nlm_SetUpdateRegion (temp);
  2437.   SetPenState (&state);
  2438.   return TRUE;
  2439. }
  2440.  
  2441. static Nlm_Boolean Nlm_ModalKey (Nlm_GraphiC w, Nlm_Char ch)
  2442.  
  2443. {
  2444.   if (Nlm_cmmdKey) {
  2445.     Nlm_Beep ();
  2446.   } else {
  2447.     Nlm_NormalKey (w, ch);
  2448.   }
  2449.   return TRUE;
  2450. }
  2451.  
  2452. static void Nlm_DrawWindow (Nlm_GraphiC w, Nlm_Boolean drawGrowIcon)
  2453.  
  2454. {
  2455.   Nlm_GraphiC     g;
  2456.   Nlm_MenuBaR     mb;
  2457.   Nlm_GraphiC     n;
  2458.   Nlm_RecT        r;
  2459.   PenState        state;
  2460.   Nlm_PortTool    temp;
  2461.   Nlm_WindowTool  wptr;
  2462.  
  2463.   wptr = Nlm_ParentWindowPtr (w);
  2464.   GetPort (&temp);
  2465.   GetPenState (&state);
  2466.   SetPort (wptr);
  2467.   Nlm_currentWindowTool = wptr;
  2468.  
  2469.   Nlm_ResetDrawingTools ();
  2470.   Nlm_ResetClip ();
  2471.   PenNormal ();
  2472.  
  2473.   BeginUpdate (wptr);
  2474.   Nlm_SetUpdateRegion (wptr);
  2475.   Nlm_RectToolToRecT (&(wptr->portRect), &r);
  2476.   Nlm_EraseRect (&r);
  2477.   if (drawGrowIcon) {
  2478.     Nlm_DrawGrowIcon (w);
  2479.   }
  2480.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2481.   if (mb != NULL) {
  2482.     Nlm_DoDraw ((Nlm_GraphiC) mb);
  2483.   }
  2484.   g = Nlm_GetChild (w);
  2485.   while (g != NULL) {
  2486.     n = Nlm_GetNext (g);
  2487.     Nlm_DoDraw (g);
  2488.     g = n;
  2489.   }
  2490.   EndUpdate (wptr);
  2491.   Nlm_ResetDrawingTools ();
  2492.   Nlm_ResetClip ();
  2493.   SetPort (temp);
  2494.   Nlm_currentWindowTool = temp;
  2495.   Nlm_SetUpdateRegion (temp);
  2496.   SetPenState (&state);
  2497. }
  2498.  
  2499. static void Nlm_DocumentDraw (Nlm_GraphiC w)
  2500.  
  2501. {
  2502.   Nlm_DrawWindow (w, TRUE);
  2503. }
  2504.  
  2505. static void Nlm_NormalDraw (Nlm_GraphiC w)
  2506.  
  2507. {
  2508.   Nlm_DrawWindow (w, FALSE);
  2509. }
  2510. #endif
  2511.  
  2512. static void Nlm_ActivateWindow (Nlm_GraphiC w, Nlm_Boolean drawGrow)
  2513.  
  2514. {
  2515.   Nlm_WndActnProc  act;
  2516.   Nlm_GraphiC      g;
  2517.   Nlm_MenuBaR      mb;
  2518.   Nlm_GraphiC      n;
  2519.   Nlm_WindowData   wdata;
  2520.  
  2521.   Nlm_UseWindow ((Nlm_WindoW) w);
  2522. #ifdef WIN_MAC
  2523.   if (drawGrow) {
  2524.     Nlm_DrawGrowIcon (w);
  2525.   }
  2526. #endif
  2527.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2528.   if (mb != NULL) {
  2529.     Nlm_DoActivate ((Nlm_GraphiC) mb, FALSE);
  2530.   }
  2531.   g = Nlm_GetChild (w);
  2532.   while (g != NULL) {
  2533.     n = Nlm_GetNext (g);
  2534.     Nlm_DoActivate (g, FALSE);
  2535.     g = n;
  2536.   }
  2537.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2538.   act = wdata.activate;
  2539.   if (act != NULL) {
  2540.     act ((Nlm_WindoW) w);
  2541.   }
  2542. }
  2543.  
  2544. static void Nlm_DocumentActivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2545.  
  2546. {
  2547.   Nlm_ActivateWindow (w, TRUE);
  2548. }
  2549.  
  2550. static void Nlm_NormalActivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2551.  
  2552. {
  2553.   Nlm_ActivateWindow (w, FALSE);
  2554. }
  2555.  
  2556. static void Nlm_DeactivateWindow (Nlm_GraphiC w, Nlm_Boolean drawGrow)
  2557.  
  2558. {
  2559.   Nlm_WndActnProc  deact;
  2560.   Nlm_GraphiC      g;
  2561.   Nlm_MenuBaR      mb;
  2562.   Nlm_GraphiC      n;
  2563.   Nlm_WindowData   wdata;
  2564.  
  2565.   Nlm_UseWindow ((Nlm_WindoW) w);
  2566. #ifdef WIN_MAC
  2567.   if (drawGrow) {
  2568.     Nlm_DrawGrowIcon (w);
  2569.   }
  2570. #endif
  2571.   mb = Nlm_GetWindowMenuBar ((Nlm_WindoW) w);
  2572.   if (mb != NULL) {
  2573.     Nlm_DoDeactivate ((Nlm_GraphiC) mb, FALSE);
  2574.   }
  2575.   g = Nlm_GetChild (w);
  2576.   while (g != NULL) {
  2577.     n = Nlm_GetNext (g);
  2578.     Nlm_DoDeactivate (g, FALSE);
  2579.     g = n;
  2580.   }
  2581.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2582.   deact = wdata.deactivate;
  2583.   if (deact != NULL) {
  2584.     deact ((Nlm_WindoW) w);
  2585.   }
  2586. }
  2587.  
  2588. static void Nlm_DocumentDeactivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2589.  
  2590. {
  2591.   Nlm_DeactivateWindow (w, TRUE);
  2592. }
  2593.  
  2594. static void Nlm_NormalDeactivate (Nlm_GraphiC w, Nlm_Boolean savePort)
  2595.  
  2596. {
  2597.   Nlm_DeactivateWindow (w, FALSE);
  2598. }
  2599.  
  2600. #ifdef WIN_MAC
  2601. static Nlm_Boolean Nlm_NormalIdle (Nlm_GraphiC w, Nlm_PoinT pt)
  2602.  
  2603. {
  2604.   Nlm_GraphiC  g;
  2605.   Nlm_GraphiC  n;
  2606.  
  2607.   g = Nlm_GetChild (w);
  2608.   while (g != NULL) {
  2609.     n = Nlm_GetNext (g);
  2610.     Nlm_DoIdle (g, Nlm_localMouse);
  2611.     g = n;
  2612.   }
  2613.   return TRUE;
  2614. }
  2615.  
  2616. static Nlm_Boolean Nlm_FloatingIdle (Nlm_GraphiC w, Nlm_PoinT pt)
  2617.  
  2618. {
  2619.   Nlm_WindoW   nw;
  2620.  
  2621.   nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2622.   Nlm_DoIdle ((Nlm_GraphiC) nw, pt);
  2623.   return TRUE;
  2624. }
  2625. #endif
  2626.  
  2627. static void Nlm_NormalDrawChar (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2628.  
  2629. {
  2630.   Nlm_DisplaY     d;
  2631.   Nlm_WindowData  wdata;
  2632.  
  2633.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2634.   d = wdata.charDisplay;
  2635.   if (d != NULL) {
  2636.     Nlm_DoSendChar ((Nlm_GraphiC) d, ch, TRUE);
  2637.   }
  2638. }
  2639.  
  2640. static void Nlm_FloatingDrawChar (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2641.  
  2642. {
  2643.   Nlm_DisplaY     d;
  2644.   Nlm_WindowData  wdata;
  2645. #ifdef WIN_MAC
  2646.   Nlm_WindoW      nw;
  2647. #endif
  2648.  
  2649.   Nlm_GetWindowData ((Nlm_WindoW) w, &wdata);
  2650.   d = wdata.charDisplay;
  2651.   if (d != NULL) {
  2652.     Nlm_DoSendChar ((Nlm_GraphiC) d, ch, TRUE);
  2653.   } else {
  2654. #ifdef WIN_MAC
  2655.     nw = Nlm_NextVisWindow ((Nlm_WindoW) w);
  2656.     Nlm_DoSendChar ((Nlm_GraphiC) nw, ch, TRUE);
  2657. #endif
  2658. #ifdef WIN_MOTIF
  2659. #endif
  2660.   }
  2661. }
  2662.  
  2663. static void Nlm_AdjustWindow (Nlm_GraphiC w, Nlm_RectPtr r,
  2664.                               Nlm_Boolean align, Nlm_Boolean savePort)
  2665.  
  2666. {
  2667.   Nlm_GraphiC  g;
  2668.   Nlm_WindoW   tempPort;
  2669.  
  2670.   tempPort = Nlm_SavePortIfNeeded (w, savePort);
  2671.   if (align) {
  2672.     g = Nlm_GetParent (w);
  2673.     Nlm_RecordRect (g, r);
  2674.     Nlm_NextPosition (g, r);
  2675.   }
  2676.   Nlm_RestorePort (tempPort);
  2677. }
  2678.  
  2679. static Nlm_GraphiC Nlm_WindowGainFocus (Nlm_GraphiC w, Nlm_Char ch, Nlm_Boolean savePort)
  2680.  
  2681. {
  2682.   Nlm_GraphiC  p;
  2683.   Nlm_GraphiC  q;
  2684.  
  2685.   q = NULL;
  2686.   p = Nlm_GetChild (w);
  2687.   while (p != NULL && q == NULL) {
  2688.     q = Nlm_DoGainFocus (p, ch, savePort);
  2689.     p = Nlm_GetNext (p);
  2690.   }
  2691.   return q;
  2692. }
  2693.  
  2694. static void Nlm_WindowLoseFocus (Nlm_GraphiC w, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2695.  
  2696. {
  2697.   Nlm_GraphiC  p;
  2698.  
  2699.   p = Nlm_GetChild (w);
  2700.   while (p != NULL) {
  2701.     Nlm_DoLoseFocus (p, excpt, savePort);
  2702.     p = Nlm_GetNext (p);
  2703.   }
  2704. }
  2705.  
  2706. extern Nlm_WindoW Nlm_DocumentWindow (Nlm_Int2 left, Nlm_Int2 top,
  2707.                                       Nlm_Int2 width, Nlm_Int2 height,
  2708.                                       Nlm_CharPtr title,
  2709.                                       Nlm_WndActnProc close,
  2710.                                       Nlm_WndActnProc resize)
  2711.  
  2712. {
  2713.   Nlm_RecT    r;
  2714.   Nlm_WindoW  w;
  2715.  
  2716.   Nlm_LoadRect (&r, left, top, width, height);
  2717.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), documentProcs);
  2718.   if (w != NULL) {
  2719. #ifdef WIN_MAC
  2720.     Nlm_NewWindow (w, DOCUMENT_STYLE, 8, TRUE, NULL, 0, title, close, resize);
  2721. #endif
  2722. #ifdef WIN_MSWIN
  2723.     Nlm_NewWindow (w, DOCUMENT_STYLE, 0, FALSE, windowclass, WS_OVERLAPPEDWINDOW, title, close, resize);
  2724. #endif
  2725. #ifdef WIN_MOTIF
  2726.     Nlm_NewWindow (w, DOCUMENT_STYLE, 0, FALSE, NULL, 0, title, close, resize);
  2727. #endif
  2728.   }
  2729.   return w;
  2730. }
  2731.  
  2732. extern Nlm_WindoW Nlm_FixedWindow (Nlm_Int2 left, Nlm_Int2 top,
  2733.                                    Nlm_Int2 width, Nlm_Int2 height,
  2734.                                    Nlm_CharPtr title, Nlm_WndActnProc close)
  2735.  
  2736. {
  2737.   Nlm_RecT    r;
  2738.   Nlm_WindoW  w;
  2739.  
  2740.   Nlm_LoadRect (&r, left, top, width, height);
  2741.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), fixedProcs);
  2742.   if (w != NULL) {
  2743. #ifdef WIN_MAC
  2744.     Nlm_NewWindow (w, FIXED_STYLE, 4, TRUE, NULL, 0, title, close, NULL);
  2745. #endif
  2746. #ifdef WIN_MSWIN
  2747.     Nlm_NewWindow (w, FIXED_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2748.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2749. #endif
  2750. #ifdef WIN_MOTIF
  2751.     Nlm_NewWindow (w, FIXED_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2752. #endif
  2753.   }
  2754.   return w;
  2755. }
  2756.  
  2757. extern Nlm_WindoW Nlm_FrozenWindow (Nlm_Int2 left, Nlm_Int2 top,
  2758.                                     Nlm_Int2 width, Nlm_Int2 height,
  2759.                                     Nlm_CharPtr title, Nlm_WndActnProc close)
  2760.  
  2761. {
  2762.   Nlm_RecT    r;
  2763.   Nlm_WindoW  w;
  2764.  
  2765.   Nlm_LoadRect (&r, left, top, width, height);
  2766.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), frozenProcs);
  2767.   if (w != NULL) {
  2768. #ifdef WIN_MAC
  2769.     Nlm_NewWindow (w, FROZEN_STYLE, 4, TRUE, NULL, 0, title, close, NULL);
  2770. #endif
  2771. #ifdef WIN_MSWIN
  2772.     Nlm_NewWindow (w, FROZEN_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2773.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2774. #endif
  2775. #ifdef WIN_MOTIF
  2776.     Nlm_NewWindow (w, FROZEN_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2777. #endif
  2778.   }
  2779.   return w;
  2780. }
  2781.  
  2782. extern Nlm_WindoW Nlm_RoundWindow (Nlm_Int2 left, Nlm_Int2 top,
  2783.                                    Nlm_Int2 width, Nlm_Int2 height,
  2784.                                    Nlm_CharPtr title, Nlm_WndActnProc close)
  2785.  
  2786. {
  2787.   Nlm_RecT    r;
  2788.   Nlm_WindoW  w;
  2789.  
  2790.   Nlm_LoadRect (&r, left, top, width, height);
  2791.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), roundProcs);
  2792.   if (w != NULL) {
  2793. #ifdef WIN_MAC
  2794.     Nlm_NewWindow (w, ROUND_STYLE, 16, TRUE, NULL, 0, title, close, NULL);
  2795. #endif
  2796. #ifdef WIN_MSWIN
  2797.     Nlm_NewWindow (w, ROUND_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED |
  2798.                    WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, title, close, NULL);
  2799. #endif
  2800. #ifdef WIN_MOTIF
  2801.     Nlm_NewWindow (w, ROUND_STYLE, 0, FALSE, NULL, 0, title, close, NULL);
  2802. #endif
  2803.   }
  2804.   return w;
  2805. }
  2806.  
  2807. extern Nlm_WindoW Nlm_AlertWindow (Nlm_Int2 left, Nlm_Int2 top,
  2808.                                    Nlm_Int2 width, Nlm_Int2 height,
  2809.                                    Nlm_WndActnProc close)
  2810.  
  2811. {
  2812.   Nlm_RecT    r;
  2813.   Nlm_WindoW  w;
  2814.  
  2815.   Nlm_LoadRect (&r, left, top, width, height);
  2816.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), alertProcs);
  2817.   if (w != NULL) {
  2818. #ifdef WIN_MAC
  2819.     Nlm_NewWindow (w, ALERT_STYLE, 1, FALSE, NULL, 0, NULL, close, NULL);
  2820. #endif
  2821. #ifdef WIN_MSWIN
  2822.     Nlm_NewWindow (w, ALERT_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2823. #endif
  2824. #ifdef WIN_MOTIF
  2825.     Nlm_NewWindow (w, ALERT_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2826. #endif
  2827.   }
  2828.   return w;
  2829. }
  2830.  
  2831. extern Nlm_WindoW Nlm_ModalWindow (Nlm_Int2 left, Nlm_Int2 top,
  2832.                                    Nlm_Int2 width, Nlm_Int2 height,
  2833.                                    Nlm_WndActnProc close)
  2834.  
  2835. {
  2836.   Nlm_RecT    r;
  2837.   Nlm_WindoW  w;
  2838.  
  2839.   Nlm_LoadRect (&r, left, top, width, height);
  2840.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), modalProcs);
  2841.   if (w != NULL) {
  2842. #ifdef WIN_MAC
  2843.     Nlm_NewWindow (w, MODAL_STYLE, 1, FALSE, NULL, 0, NULL, close, NULL);
  2844. #endif
  2845. #ifdef WIN_MSWIN
  2846.     Nlm_NewWindow (w, MODAL_STYLE, 0, FALSE, windowclass, WS_POPUP |
  2847.                    WS_CAPTION | WS_SYSMENU, "", close, NULL);
  2848. #endif
  2849. #ifdef WIN_MOTIF
  2850.     Nlm_NewWindow (w, MODAL_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2851. #endif
  2852.   }
  2853.   return w;
  2854. }
  2855.  
  2856. extern Nlm_WindoW Nlm_FloatingWindow (Nlm_Int2 left, Nlm_Int2 top,
  2857.                                       Nlm_Int2 width, Nlm_Int2 height,
  2858.                                       Nlm_WndActnProc close)
  2859.  
  2860. {
  2861.   Nlm_RecT    r;
  2862.   Nlm_WindoW  w;
  2863.  
  2864.   Nlm_LoadRect (&r, left, top, width, height);
  2865.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), floatingProcs);
  2866.   if (w != NULL) {
  2867. #ifdef WIN_MAC
  2868.     Nlm_NewWindow (w, FLOATING_STYLE, 17, TRUE, NULL, 0, NULL, close, NULL);
  2869. #endif
  2870. #ifdef WIN_MSWIN
  2871.     Nlm_NewWindow (w, FLOATING_STYLE, 0, FALSE, windowclass, WS_POPUP |
  2872.                    WS_CAPTION | WS_SYSMENU, "", close, NULL);
  2873. #endif
  2874. #ifdef WIN_MOTIF
  2875.     Nlm_NewWindow (w, FLOATING_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2876. #endif
  2877.   }
  2878.   return w;
  2879. }
  2880.  
  2881. extern Nlm_WindoW Nlm_ShadowWindow (Nlm_Int2 left, Nlm_Int2 top,
  2882.                                     Nlm_Int2 width, Nlm_Int2 height,
  2883.                                     Nlm_WndActnProc close)
  2884.  
  2885. {
  2886.   Nlm_RecT    r;
  2887.   Nlm_WindoW  w;
  2888.  
  2889.   Nlm_LoadRect (&r, left, top, width, height);
  2890.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), shadowProcs);
  2891.   if (w != NULL) {
  2892. #ifdef WIN_MAC
  2893.     Nlm_NewWindow (w, SHADOW_STYLE, 3, FALSE, NULL, 0, NULL, close, NULL);
  2894. #endif
  2895. #ifdef WIN_MSWIN
  2896.     Nlm_NewWindow (w, SHADOW_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2897. #endif
  2898. #ifdef WIN_MOTIF
  2899.     Nlm_NewWindow (w, SHADOW_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2900. #endif
  2901.   }
  2902.   return w;
  2903. }
  2904.  
  2905. extern Nlm_WindoW Nlm_PlainWindow (Nlm_Int2 left, Nlm_Int2 top,
  2906.                                    Nlm_Int2 width, Nlm_Int2 height,
  2907.                                    Nlm_WndActnProc close)
  2908.  
  2909. {
  2910.   Nlm_RecT    r;
  2911.   Nlm_WindoW  w;
  2912.  
  2913.   Nlm_LoadRect (&r, left, top, width, height);
  2914.   w = Nlm_MakeWindowLink (&r, sizeof (Nlm_WindowRec), plainProcs);
  2915.   if (w != NULL) {
  2916. #ifdef WIN_MAC
  2917.     Nlm_NewWindow (w, PLAIN_STYLE, 2, FALSE, NULL, 0, NULL, close, NULL);
  2918. #endif
  2919. #ifdef WIN_MSWIN
  2920.     Nlm_NewWindow (w, PLAIN_STYLE, 0, FALSE, windowclass, WS_OVERLAPPED, "", close, NULL);
  2921. #endif
  2922. #ifdef WIN_MOTIF
  2923.     Nlm_NewWindow (w, PLAIN_STYLE, 0, FALSE, NULL, 0, "", close, NULL);
  2924. #endif
  2925.   }
  2926.   return w;
  2927. }
  2928.  
  2929. #ifdef WIN_MOTIF
  2930. static void Nlm_SetCursor (Cursor cursor)
  2931.  
  2932. {
  2933.   Nlm_MainTool  man;
  2934.   Nlm_WindoW    w;
  2935.   Window        xtw;
  2936.  
  2937.   if (Nlm_currentXDisplay != NULL) {
  2938.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  2939.     while (w != NULL) {
  2940.       if (! Nlm_IsWindowDying (w)) {
  2941.         man = Nlm_GetWindowMain (w);
  2942.         xtw = XtWindow (man);
  2943.         if (xtw != 0) {
  2944.           XDefineCursor (Nlm_currentXDisplay, xtw, cursor);
  2945.         }
  2946.       }
  2947.       w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  2948.     }
  2949.     currentCursor = cursor;
  2950.     XSync (Nlm_currentXDisplay, FALSE);
  2951.   }
  2952. }
  2953. #endif
  2954.  
  2955. extern void Nlm_ArrowCursor (void)
  2956.  
  2957. {
  2958. #ifdef WIN_MAC
  2959.   SetCursor (&qd.arrow);
  2960. #endif
  2961. #ifdef WIN_MSWIN
  2962.   currentCursor = LoadCursor (NULL, IDC_ARROW);
  2963.   SetCursor (currentCursor);
  2964. #endif
  2965. #ifdef WIN_MOTIF
  2966.   Nlm_SetCursor (arrow);
  2967. #endif
  2968. }
  2969.  
  2970. extern void Nlm_CrossCursor (void)
  2971.  
  2972. {
  2973. #ifdef WIN_MAC
  2974.   SetCursor (&cross);
  2975. #endif
  2976. #ifdef WIN_MSWIN
  2977.   currentCursor = LoadCursor (NULL, IDC_CROSS);
  2978.   SetCursor (currentCursor);
  2979. #endif
  2980. #ifdef WIN_MOTIF
  2981.   Nlm_SetCursor (cross);
  2982. #endif
  2983. }
  2984.  
  2985. extern void Nlm_IBeamCursor (void)
  2986.  
  2987. {
  2988. #ifdef WIN_MAC
  2989.   SetCursor (&iBeam);
  2990. #endif
  2991. #ifdef WIN_MSWIN
  2992.   currentCursor = LoadCursor (NULL, IDC_IBEAM);
  2993.   SetCursor (currentCursor);
  2994. #endif
  2995. #ifdef WIN_MOTIF
  2996.   Nlm_SetCursor (iBeam);
  2997. #endif
  2998. }
  2999.  
  3000. extern void Nlm_PlusCursor (void)
  3001.  
  3002. {
  3003. #ifdef WIN_MAC
  3004.   SetCursor (&plus);
  3005. #endif
  3006. #ifdef WIN_MSWIN
  3007.   currentCursor = LoadCursor (NULL, IDC_CROSS);
  3008.   SetCursor (currentCursor);
  3009. #endif
  3010. #ifdef WIN_MOTIF
  3011.   Nlm_SetCursor (plus);
  3012. #endif
  3013. }
  3014.  
  3015. extern void Nlm_WatchCursor (void)
  3016.  
  3017. {
  3018. #ifdef WIN_MAC
  3019.   SetCursor (&watch);
  3020. #endif
  3021. #ifdef WIN_MSWIN
  3022.   currentCursor = LoadCursor (NULL, IDC_WAIT);
  3023.   SetCursor (currentCursor);
  3024. #endif
  3025. #ifdef WIN_MOTIF
  3026.   Nlm_SetCursor (watch);
  3027. #endif
  3028. }
  3029.  
  3030. extern void Nlm_ProgramPath (Nlm_CharPtr buf, Nlm_sizeT maxsize)
  3031.  
  3032. {
  3033. #ifdef WIN_MAC
  3034.   WDPBRec      block;
  3035.   Nlm_Char     directory [PATH_MAX];
  3036.   Nlm_Int4     dirID;
  3037.   OSErr        err;
  3038.   CInfoPBRec   params;
  3039.   Nlm_Char     temp [PATH_MAX]; /* dgg was PATH_MAX, need > 64 !! */
  3040.   Nlm_CharPtr  tmp;
  3041.   short        vRefNum;
  3042. #endif
  3043. #ifdef WIN_MSWIN
  3044.   Nlm_Char     path [PATH_MAX];
  3045. #endif
  3046. #ifdef WIN_MOTIF
  3047.   Nlm_Char     path [PATH_MAX];
  3048.   Nlm_CharPtr  pth;
  3049.   Nlm_CharPtr  ptr;
  3050. #endif
  3051.  
  3052.   if (buf != NULL && maxsize > 0) {
  3053. #ifdef WIN_MAC
  3054.     memset (&block, 0, sizeof (WDPBRec));
  3055.     block.ioNamePtr = NULL;
  3056.     block.ioVRefNum = apRefNum;
  3057.     block.ioWDIndex = 0;
  3058.     block.ioWDProcID = 0;
  3059.     PBGetWDInfo (&block, FALSE);
  3060.     dirID = block.ioWDDirID;
  3061.     vRefNum = block.ioWDVRefNum;
  3062.     temp [0] = '\0';
  3063.     params.dirInfo.ioNamePtr = (StringPtr) directory;
  3064.     params.dirInfo.ioDrParID = dirID;
  3065.     do {
  3066.       params.dirInfo.ioVRefNum = vRefNum;
  3067.       params.dirInfo.ioFDirIndex = -1;
  3068.       params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID;
  3069.       err = PBGetCatInfo (¶ms, FALSE);
  3070. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3071.   p2cstr ((StringPtr) directory);
  3072. #endif
  3073. #ifdef COMP_THINKC
  3074.   PtoCstr ((StringPtr) directory);
  3075. #endif
  3076.       Nlm_StringCat (directory, DIRDELIMSTR);
  3077.       Nlm_StringCat (directory, temp);
  3078.       Nlm_StringCpy (temp, directory);
  3079.     } while (params.dirInfo.ioDrDirID != fsRtDirID);
  3080.     tmp = Nlm_StringMove (directory, temp);
  3081.     tmp = Nlm_StringMove (tmp, (Nlm_CharPtr) apName);
  3082.     Nlm_StringNCpy (buf, directory, maxsize);
  3083. #endif
  3084. #ifdef WIN_MSWIN
  3085.     if (GetModuleFileName (Nlm_currentHInst, path, sizeof (path)) > 0) {
  3086.       Nlm_StringNCpy (buf, path, maxsize);
  3087.     } else {
  3088.       *buf = '\0';
  3089.     }
  3090. #endif
  3091. #ifdef OS_UNIX
  3092.     ptr = statargv [0];
  3093.     if (ptr [0] == DIRDELIMCHR) {
  3094.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3095.     } else if (getcwd (path, sizeof (path)) != NULL) {
  3096.       ptr = statargv [0];
  3097.       while (ptr [0] == '.' || ptr [0] == DIRDELIMCHR) {
  3098.         if (ptr [0] == '.') {
  3099.           if (ptr [1] == '.' && ptr [2] == DIRDELIMCHR) {
  3100.             ptr += 3;
  3101.             pth = StringRChr (path, DIRDELIMCHR);
  3102.             if (pth != NULL) {
  3103.               *pth = '\0';
  3104.             }
  3105.           } else if (ptr [1] == DIRDELIMCHR) {
  3106.             ptr += 2;
  3107.           } else {
  3108.             ptr++;
  3109.           }
  3110.         } else if (ptr [0] == DIRDELIMCHR) {
  3111.           ptr++;
  3112.         } else {
  3113.           ptr++;
  3114.         }
  3115.       }
  3116.       FileBuildPath (path, NULL, ptr);
  3117.       Nlm_StringNCpy (buf, path, maxsize);
  3118.     } else {
  3119.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3120.     }
  3121. #endif
  3122. #ifdef OS_VMS
  3123.     if (statargv != NULL && statargv [0] != NULL) {
  3124.       Nlm_StringNCpy (buf, statargv [0], maxsize);
  3125.     }
  3126. #endif
  3127.   }
  3128. }
  3129.  
  3130. #ifdef WIN_MAC
  3131.  
  3132. static void Nlm_HandleEvent (void)
  3133.  
  3134. {
  3135.   Nlm_Int2        key;
  3136.   Nlm_PointTool   ptool;
  3137.   Nlm_PoinT       where;
  3138.   Nlm_Int2        windowLoc;
  3139.   Nlm_WindowTool  wptr;
  3140.  
  3141.   Nlm_PointToolToPoinT (Nlm_currentEvent.where, &Nlm_globalMouse);
  3142.   Nlm_localMouse = Nlm_globalMouse;
  3143.   Nlm_GlobalToLocal (&Nlm_localMouse);
  3144.   Nlm_currentKey = '\0';
  3145.   key = Nlm_currentEvent.modifiers;
  3146.   Nlm_cmmdKey = ((key & 256) != 0);
  3147.   Nlm_ctrlKey = FALSE;
  3148.   Nlm_shftKey = ((key & 512) != 0);
  3149.   Nlm_optKey = ((key & 2048) != 0);
  3150.   Nlm_dblClick = FALSE;
  3151.   frontWindow = Nlm_FindWindowRec (FrontWindow ());
  3152.   Nlm_theWindow = Nlm_FindWindowRec ((Nlm_WindowTool) Nlm_currentEvent.message);
  3153.   chosenWindow = Nlm_theWindow;
  3154.   switch (Nlm_currentEvent.what) {
  3155.     case mouseDown:
  3156.       Nlm_PoinTToPointTool (Nlm_globalMouse, &ptool);
  3157.       windowLoc = FindWindow (ptool, &wptr);
  3158.       chosenWindow = Nlm_FindWindowRec (wptr);
  3159.       Nlm_DoClick ((Nlm_GraphiC) frontWindow, Nlm_globalMouse);
  3160.       break;
  3161.     case keyDown:
  3162.       Nlm_currentKey = (Nlm_Char) (Nlm_currentEvent.message % 256);
  3163.       if (keyAction != NULL) {
  3164.         keyAction (Nlm_currentKey);
  3165.       }
  3166.       Nlm_DoKey ((Nlm_GraphiC) frontWindow, Nlm_currentKey);
  3167.       break;
  3168.     case autoKey:
  3169.       if (! Nlm_cmmdKey) {
  3170.         Nlm_currentKey = (Nlm_Char) (Nlm_currentEvent.message % 256);
  3171.         Nlm_DoKey ((Nlm_GraphiC) frontWindow, Nlm_currentKey);
  3172.       }
  3173.       break;
  3174.     case updateEvt:
  3175.       Nlm_DoDraw ((Nlm_GraphiC) Nlm_theWindow);
  3176.       break;
  3177.     case osEvt:
  3178.       if (((Nlm_currentEvent.message & osEvtMessageMask) >> 24) == suspendResumeMessage) {
  3179.         if (Nlm_currentEvent.message & resumeFlag) {
  3180.           if (Nlm_currentEvent.message & convertClipboardFlag) {
  3181.             TEFromScrap ();
  3182.           }
  3183.         } else {
  3184.           ZeroScrap ();
  3185.           TEToScrap ();
  3186.         }
  3187.       }
  3188.       break;
  3189.     case activateEvt:
  3190.       if (Nlm_currentEvent.modifiers & 01) {
  3191.         Nlm_DoActivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3192.       } else {
  3193.         Nlm_DoDeactivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3194.       }
  3195.       break;
  3196.     case diskEvt:
  3197.       if (HiWord (Nlm_currentEvent.message) != 0) {
  3198.         where.x = 90;
  3199.         where.y = 100;
  3200.         Nlm_PoinTToPointTool (where, &ptool);
  3201.         DIBadMount (ptool, Nlm_currentEvent.message);
  3202.       }
  3203.       break;
  3204.     case kHighLevelEvent:
  3205. #ifdef DCLAP
  3206.                 // 68k mac app is bombing here now (not before) ... ?? why
  3207.             if (StrNCmp((char*)&Nlm_currentEvent.where.v,"oapp",4)==0) break;
  3208. #endif
  3209.       AEProcessAppleEvent (&Nlm_currentEvent);
  3210.       break;
  3211.     default:
  3212.       break;
  3213.   }
  3214. }
  3215.  
  3216. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3217.  
  3218. {
  3219.   return TRUE;
  3220. }
  3221.  
  3222. static void Nlm_ReturnCursor (Cursor *cursor, Nlm_Int2 cursorID)
  3223.  
  3224. {
  3225.   CursHandle  hCurs;
  3226.   CursPtr     pCurs;
  3227.  
  3228.   hCurs = GetCursor (cursorID);
  3229.   if (hCurs != NULL) {
  3230.     HLock ((Handle) hCurs);
  3231.     pCurs = (CursPtr) *((Handle) hCurs);
  3232.     *cursor = *pCurs;
  3233.     HUnlock ((Handle) hCurs);
  3234.   } else {
  3235.     *cursor = qd.arrow;
  3236.   }
  3237. }
  3238.  
  3239. static Nlm_Boolean Nlm_SetupWindows (void)
  3240.  
  3241. {
  3242.   Nlm_PoinT  pt;
  3243.   Nlm_RecT   r;
  3244.   SysEnvRec  sysenv;
  3245.  
  3246.   Nlm_ReturnCursor (&cross, 2);
  3247.   Nlm_ReturnCursor (&iBeam, 1);
  3248.   Nlm_ReturnCursor (&plus, 3);
  3249.   Nlm_ReturnCursor (&watch, 4);
  3250.   Nlm_WatchCursor ();
  3251.   Nlm_ClearKeys ();
  3252.   Nlm_LoadPt (&pt, 0, 0);
  3253.   Nlm_RectToolToRecT (&(qd.screenBits.bounds), &screenBitBounds);
  3254.   r = screenBitBounds;
  3255.   Nlm_screenRect = screenBitBounds;
  3256.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3257.   Nlm_systemWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3258.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, (Nlm_GraphiC) Nlm_systemWindow,
  3259.                        NULL, NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3260.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3261.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3262.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3263.   Nlm_LoadRect (&r, 0, 0, 0, 0);
  3264.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_systemWindow, NULL, NULL,
  3265.                        NULL, NULL, systemProcs, NULL, &r, TRUE, TRUE);
  3266.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_systemWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3267.   Nlm_LoadWindowData (Nlm_systemWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3268.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3269.   dyingWindow = NULL;
  3270.   frontWindow = Nlm_desktopWindow;
  3271.   theActiveWindow = Nlm_desktopWindow;
  3272.   chosenWindow = Nlm_desktopWindow;
  3273.   Nlm_theWindow = Nlm_desktopWindow;
  3274.   Nlm_currentWindowTool = NULL;
  3275.   quitProgram = FALSE;
  3276.  
  3277.   Nlm_SetUpDrawingTools ();
  3278.  
  3279.   Nlm_hScrollBarHeight = 16;
  3280.   Nlm_vScrollBarWidth = 16;
  3281.  
  3282.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 4;
  3283.   Nlm_dialogTextHeight = Nlm_stdLineHeight + 4;
  3284.   
  3285.   lastTimerTime = Nlm_ComputerTime ();
  3286.   timerAction = NULL;
  3287.   keyAction = NULL;
  3288.   SysEnvirons (1, &sysenv);
  3289.   hasColorQD = sysenv.hasColorQD;
  3290.   return TRUE;
  3291. }
  3292. #endif
  3293.  
  3294. #ifdef WIN_MSWIN
  3295.  
  3296. /* Message cracker functions */
  3297.  
  3298. static void MyCls_OnMouseMove (HWND hwnd, int x, int y, UINT keyFlags)
  3299.  
  3300. {
  3301.   SetCursor (currentCursor);
  3302. }
  3303.  
  3304. static void MyCls_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  3305.  
  3306. {
  3307.   Nlm_GraphiC  g;
  3308.   Nlm_MenuBaR  mb;
  3309.  
  3310.   Nlm_currentId = id;
  3311.   Nlm_currentHwndCtl = hwndCtl;
  3312.   Nlm_currentCode = codeNotify;
  3313.  
  3314.   if (hwndCtl == NULL) {
  3315.     mb = Nlm_GetWindowMenuBar (Nlm_theWindow);
  3316.     Nlm_DoCommand ((Nlm_GraphiC) mb);
  3317.   } else {
  3318.     g = (Nlm_GraphiC) GetProp (hwndCtl, (LPSTR) "Nlm_VibrantProp");
  3319.     (void) (Nlm_GetEnabled (g) &&
  3320.             Nlm_GetVisible (g) &&
  3321.             Nlm_DoCommand (g));
  3322.   }
  3323. }
  3324.  
  3325. static void MyCls_OnHVScroll (HWND hwnd, HWND hwndCtl, UINT code, int pos)
  3326.  
  3327. {
  3328.   Nlm_GraphiC  g;
  3329.  
  3330.   Nlm_currentHwndCtl = hwndCtl;
  3331.   Nlm_currentCode = code;
  3332.   Nlm_currentPos = pos;
  3333.  
  3334.   if (hwndCtl != NULL) {
  3335.     g = (Nlm_GraphiC) GetProp (hwndCtl, (LPSTR) "Nlm_VibrantProp");
  3336.     (void) (Nlm_GetEnabled (g) &&
  3337.             Nlm_GetVisible (g) &&
  3338.             Nlm_DoCommand (g));
  3339.   }
  3340. }
  3341.  
  3342. static void MyCls_OnClose (HWND hwnd)
  3343.  
  3344. {
  3345.   Nlm_WndActnProc  cls;
  3346.   Nlm_WindowData   wdata;
  3347.  
  3348.   Nlm_GetWindowData (Nlm_theWindow, &wdata);
  3349.   cls = wdata.close;
  3350.   if (cls != NULL) {
  3351.     cls (Nlm_theWindow);
  3352.   }
  3353. }
  3354.  
  3355. static void MyCls_OnActivate (HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized)
  3356.  
  3357. {
  3358.   if (state != 0) {
  3359.     Nlm_DoActivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3360.   } else {
  3361.     Nlm_DoDeactivate ((Nlm_GraphiC) Nlm_theWindow, FALSE);
  3362.   }
  3363. }
  3364.  
  3365. static void MyCls_OnSize (HWND hwnd, UINT state, int cx, int cy)
  3366.  
  3367. {
  3368.   Nlm_RecT         r;
  3369.   Nlm_WndActnProc  resize;
  3370.   Nlm_RectTool     rtool;
  3371.   Nlm_WindowData   wdata;
  3372.  
  3373.   if (Nlm_WindowHasBeenShown (Nlm_theWindow) &&
  3374.       Nlm_GetVisible ((Nlm_GraphiC) Nlm_theWindow)) {
  3375.     Nlm_GetWindowData (Nlm_theWindow, &wdata);
  3376.     resize = wdata.resize;
  3377.     if (resize != NULL) {
  3378.       GetWindowRect (hwnd, &rtool);
  3379.       Nlm_RectToolToRecT (&rtool, &r);
  3380.       Nlm_SetRect ((Nlm_GraphiC) Nlm_theWindow, &r);
  3381.       resize (Nlm_theWindow);
  3382.     }
  3383.   }
  3384. }
  3385.  
  3386. static void MyCls_OnChar (HWND hwnd, UINT ch, int cRepeat)
  3387.  
  3388. {
  3389.   handlechar = FALSE;
  3390.   if (ch == '\t') {
  3391.     Nlm_DoSendFocus ((Nlm_GraphiC) Nlm_theWindow, (Nlm_Char) ch);
  3392.   } else if (ch == '\n' || ch == '\r') {
  3393.     Nlm_DoSendFocus ((Nlm_GraphiC) Nlm_theWindow, (Nlm_Char) ch);
  3394.   } else {
  3395.     handlechar = TRUE;
  3396.   }
  3397. }
  3398.  
  3399. /*
  3400. *  Note that the WM_SIZE message will trigger the resize callback whenever
  3401. *  a visible window is resized, including the initial sizing when a window
  3402. *  is first displayed.
  3403. */
  3404.  
  3405. LRESULT CALLBACK EXPORT MainProc (HWND hwnd, UINT message,
  3406.                                   WPARAM wParam, LPARAM lParam)
  3407.  
  3408. {
  3409.   MINMAXINFO FAR*  lpmmi;
  3410.   HDC              tempHDC;
  3411.   HWND             tempHWnd;
  3412.  
  3413.   if (Nlm_VibrantDisabled ()) {
  3414.     return DefWindowProc (hwnd, message, wParam, lParam);
  3415.   }
  3416.  
  3417.   mainwndrsult = 0;
  3418.   tempHWnd = Nlm_currentHWnd;
  3419.   tempHDC = Nlm_currentHDC;
  3420.   Nlm_theWindow = (Nlm_WindoW) GetProp (hwnd, (LPSTR) "Nlm_VibrantProp");
  3421.   Nlm_currentHWnd = hwnd;
  3422.   Nlm_currentHDC = Nlm_GetWindowPort (Nlm_theWindow);
  3423.   Nlm_currentWindowTool = hwnd;
  3424.   Nlm_currentKey = '\0';
  3425.   Nlm_currentWParam = wParam;
  3426.   Nlm_currentLParam = lParam;
  3427.   Nlm_cmmdKey = FALSE;
  3428.   Nlm_ctrlKey = FALSE;
  3429.   Nlm_optKey = FALSE;
  3430.   Nlm_shftKey = FALSE;
  3431.   Nlm_dblClick = FALSE;
  3432.   switch (message) {
  3433.     case WM_MOUSEMOVE:
  3434.       HANDLE_WM_MOUSEMOVE (hwnd, wParam, lParam, MyCls_OnMouseMove);
  3435.       break;
  3436.     case WM_COMMAND:
  3437.       HANDLE_WM_COMMAND (hwnd, wParam, lParam, MyCls_OnCommand);
  3438.       break;
  3439.     case WM_HSCROLL:
  3440.       HANDLE_WM_HSCROLL (hwnd, wParam, lParam, MyCls_OnHVScroll);
  3441.       break;
  3442.     case WM_VSCROLL:
  3443.       HANDLE_WM_VSCROLL (hwnd, wParam, lParam, MyCls_OnHVScroll);
  3444.       break;
  3445.     case WM_CLOSE:
  3446.       HANDLE_WM_CLOSE (hwnd, wParam, lParam, MyCls_OnClose);
  3447.       break;
  3448.     case WM_ACTIVATE:
  3449.       mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3450.       HANDLE_WM_ACTIVATE (hwnd, wParam, lParam, MyCls_OnActivate);
  3451.       break;
  3452.     case WM_SIZE:
  3453.       HANDLE_WM_SIZE (hwnd, wParam, lParam, MyCls_OnSize);
  3454.       break;
  3455.     case WM_GETMINMAXINFO:
  3456.       lpmmi = (MINMAXINFO FAR*) lParam;
  3457.       lpmmi->ptMaxTrackSize.x = 30000;
  3458.       lpmmi->ptMaxTrackSize.y = 30000;
  3459.       break;
  3460.     case WM_DESTROY:
  3461.       break;
  3462. #if !defined(WIN32) && !defined(WIN32BOR)
  3463.     case WM_CTLCOLOR:
  3464.       if (lParam == CTLCOLOR_STATIC || lParam == CTLCOLOR_LISTBOX ||
  3465.           lParam == CTLCOLOR_EDIT || lParam == CTLCOLOR_BTN) {
  3466.         mainwndrsult = (long) (int) GetStockObject (WHITE_BRUSH);
  3467.         SetBkColor ((HDC) wParam, RGB (255, 255, 255));
  3468.         SetTextColor ((HDC) wParam, RGB (0, 0, 0));
  3469.       } else {
  3470.         mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3471.       }
  3472.       break;
  3473. #else
  3474.     case WM_CTLCOLORSTATIC:
  3475.     case WM_CTLCOLORLISTBOX:
  3476.     case WM_CTLCOLOREDIT:
  3477.     case WM_CTLCOLORBTN:
  3478.       mainwndrsult = (long) GetStockObject (WHITE_BRUSH);
  3479.       SetBkColor ((HDC) wParam, RGB (255, 255, 255));
  3480.       SetTextColor ((HDC) wParam, RGB (0, 0, 0));
  3481.       break;
  3482. #endif
  3483.     case WM_CHAR:
  3484. #ifdef DCLAP
  3485.             /* Nlm_cmmdKey= (((unsigned long)lParam >> 29) & 1); /* alt key flag */
  3486. #endif
  3487.       HANDLE_WM_CHAR (hwnd, wParam, lParam, MyCls_OnChar);
  3488.       if (handlechar) {
  3489.         mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3490.       }
  3491.       break;
  3492.     default:
  3493.       mainwndrsult = DefWindowProc (hwnd, message, wParam, lParam);
  3494.       break;
  3495.   }
  3496.   Nlm_currentHWnd = tempHWnd;
  3497.   Nlm_currentHDC = tempHDC;
  3498.   Nlm_currentWindowTool = tempHWnd;
  3499.   return mainwndrsult;
  3500. }
  3501.  
  3502. void FAR PASCAL EXPORT MetronomeProc (HWND hwnd, UINT message,
  3503.                                       WPARAM wParam, LPARAM lParam)
  3504.  
  3505. {
  3506.   if (Nlm_VibrantDisabled ()) {
  3507.     return;
  3508.   }
  3509.   if (message == WM_TIMER && timerAction != NULL) {
  3510.     timerAction ();
  3511.   }
  3512. }
  3513.  
  3514. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3515.  
  3516. {
  3517.   Nlm_Boolean  rsult;
  3518.   WNDCLASS     wc;
  3519.  
  3520.   rsult = FALSE;
  3521.   wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  3522.   wc.lpfnWndProc = MainProc;
  3523.   wc.cbClsExtra = 0;
  3524.   wc.cbWndExtra = 0;
  3525.   wc.hInstance = Nlm_currentHInst;
  3526.   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  3527.   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  3528.   /*
  3529.   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  3530.   */
  3531.   wc.hbrBackground = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
  3532.   wc.lpszMenuName = NULL;
  3533.   sprintf (windowclass, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  3534.   wc.lpszClassName = windowclass;
  3535.   rsult = (Nlm_Boolean) RegisterClass (&wc);
  3536.   return rsult;
  3537. }
  3538.  
  3539. static Nlm_Boolean Nlm_SetupWindows (void)
  3540.  
  3541. {
  3542.   Nlm_Int2   height;
  3543.   WNDPROC    lpfnTimerProc;
  3544.   Nlm_PoinT  pt;
  3545.   Nlm_RecT   r;
  3546.   Nlm_Int2   width;
  3547.  
  3548.   width = GetSystemMetrics (SM_CXSCREEN);
  3549.   height = GetSystemMetrics (SM_CYSCREEN);
  3550.   Nlm_LoadRect (&screenBitBounds, 0, 0, width, height);
  3551.   Nlm_LoadPt (&pt, 0, 0);
  3552.   r = screenBitBounds;
  3553.   Nlm_screenRect = screenBitBounds;
  3554.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3555.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, NULL, NULL,
  3556.                        NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3557.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3558.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3559.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3560.   Nlm_systemWindow = NULL;
  3561.   Nlm_currentHWnd = NULL;
  3562.   Nlm_currentHDC = NULL;
  3563.   Nlm_currentWindowTool = NULL;
  3564.   quitProgram = FALSE;
  3565.   
  3566.   Nlm_SetUpDrawingTools ();
  3567.  
  3568.   Nlm_hScrollBarHeight = GetSystemMetrics (SM_CYHSCROLL);
  3569.   Nlm_vScrollBarWidth = GetSystemMetrics (SM_CXVSCROLL);
  3570.  
  3571.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 8;
  3572.   Nlm_dialogTextHeight = Nlm_stdFontHeight * 3 / 2;
  3573.   
  3574.   currentCursor = LoadCursor (NULL, IDC_WAIT);
  3575.   
  3576.   lpfnTimerProc = (WNDPROC) MakeProcInstance ((FARPROC) MetronomeProc, Nlm_currentHInst);
  3577.   if (lpfnTimerProc != NULL) {
  3578.     timerID = SetTimer (NULL, 1, 50, (TIMERPROC) lpfnTimerProc);
  3579.   }
  3580.   timerAction = NULL;
  3581.   keyAction = NULL;
  3582.   return TRUE;
  3583. }
  3584. #endif
  3585.  
  3586. #ifdef WIN_MOTIF
  3587. static void Nlm_WindowTimer (XtPointer client_data, XtIntervalId *id)
  3588.  
  3589. {
  3590.   if (! quitProgram) {
  3591.     windowTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_WindowTimer, NULL);
  3592.   }
  3593.   if (timerAction != NULL) {
  3594.     timerAction ();
  3595.   }
  3596. }
  3597.  
  3598. extern Nlm_Boolean Nlm_RegisterWindows (void)
  3599.  
  3600. {
  3601.   windowTimer = XtAppAddTimeOut (Nlm_appContext, 50, Nlm_WindowTimer, NULL);
  3602.   return TRUE;
  3603. }
  3604.  
  3605.  
  3606. extern XFontStruct *Nlm_XLoadQueryFont PROTO((Display *, Nlm_CharPtr, Nlm_Boolean));
  3607. static Nlm_Boolean Nlm_SetupWindows (void)
  3608.  
  3609. {
  3610.   char       appname [128];
  3611.   Nlm_Int4   height;
  3612.   Nlm_PoinT  pt;
  3613.   Nlm_RecT   r;
  3614.   Nlm_Int4   width;
  3615.  
  3616.   Nlm_desktopWindow = NULL;
  3617.   Nlm_systemWindow = NULL;
  3618.   Nlm_currentXDisplay = NULL;
  3619.   Nlm_currentXScreen = 0;
  3620.   Nlm_currentXWindow = 0;
  3621.   Nlm_currentXGC = NULL;
  3622.   Nlm_currentWindowTool = NULL;
  3623.   quitProgram = FALSE;
  3624.   timerAction = NULL;
  3625.   keyAction = NULL;
  3626.  
  3627. #ifdef NOT_NOW_DCLAP
  3628.     {
  3629.   Widget toplevel;
  3630.   char* appclass= "Vibrant";
  3631.   Nlm_appContext= NULL;
  3632.   toplevel = XtAppInitialize( &Nlm_appContext, appclass, 
  3633.                          NULL, 0, /*XrmOptionDescList options, XtNumber (options),*/
  3634.              &statargc, statargv, 
  3635.                          colorXresources, 
  3636.              NULL, 0); /*ArgList_override_defaults, argnum);*/
  3637.   if (Nlm_appContext == NULL) return FALSE;
  3638.   }
  3639.  
  3640. #else
  3641.   XtToolkitInitialize ();
  3642.   Nlm_appContext = XtCreateApplicationContext ();
  3643.   if (Nlm_appContext == NULL) {
  3644.     return FALSE;
  3645.   }
  3646. #ifdef DCLAP
  3647.   XtAppSetFallbackResources( Nlm_appContext, colorXresources);
  3648. #endif
  3649. #endif
  3650.  
  3651.   Nlm_currentXDisplay = XOpenDisplay (NULL);
  3652.   if (Nlm_currentXDisplay == NULL) {
  3653.     fprintf (stderr, "Vibrant applications require X Windows\n");
  3654.     return FALSE;
  3655.   }
  3656.   Nlm_currentXScreen = DefaultScreen (Nlm_currentXDisplay);
  3657.   width =  DisplayWidth (Nlm_currentXDisplay, Nlm_currentXScreen);
  3658.   height = DisplayHeight (Nlm_currentXDisplay, Nlm_currentXScreen);
  3659.  
  3660.   Nlm_LoadRect (&screenBitBounds, 0, 0, (Nlm_Int2) width, (Nlm_Int2) height);
  3661.   Nlm_LoadPt (&pt, 0, 0);
  3662.   r = screenBitBounds;
  3663.   Nlm_screenRect = screenBitBounds;
  3664.   Nlm_desktopWindow = (Nlm_WindoW) Nlm_HandNew (sizeof (Nlm_WindowRec));
  3665.   Nlm_LoadGraphicData ((Nlm_GraphiC) Nlm_desktopWindow, NULL, NULL,
  3666.                        NULL, NULL, desktopProcs, NULL, &r, TRUE, TRUE);
  3667.   Nlm_LoadBoxData ((Nlm_BoX) Nlm_desktopWindow, pt, pt, pt, 0, 0, 0, 0, 0, 0, 0, 0);
  3668.   Nlm_LoadWindowData (Nlm_desktopWindow, NULL, NULL, NULL, NULL, &r, &r, &r, NULL,
  3669.                       NULL, NULL, NULL, NULL, NULL, NULL, TRUE, FALSE, NULL, NULL, NULL);
  3670.   Nlm_StringNCpy (appname, statargv [0], sizeof (appname));
  3671.   TO_UPPER (appname [0]);
  3672.  
  3673. #ifdef DCLAP
  3674.   Nlm_StringNCpy (Nlm_appname, appname, sizeof (Nlm_appname));
  3675. #endif
  3676.  
  3677.   XtDisplayInitialize (Nlm_appContext, Nlm_currentXDisplay, (String) appname,
  3678.                        (String) "Vibrant", (XrmOptionDescRec *) NULL,
  3679.                        (Cardinal) 0, &statargc, statargv);
  3680.   firstGC = XCreateGC (Nlm_currentXDisplay,
  3681.                        RootWindow (Nlm_currentXDisplay,
  3682.                                    Nlm_currentXScreen),
  3683.                        0, NULL);
  3684.   Nlm_currentXGC = firstGC;
  3685.   Nlm_SetUpDrawingTools ();
  3686.  
  3687.   Nlm_hScrollBarHeight = 15;
  3688.   Nlm_vScrollBarWidth = 15;
  3689.  
  3690.   Nlm_popupMenuHeight = Nlm_stdLineHeight + 10;
  3691.   Nlm_dialogTextHeight = Nlm_stdLineHeight + 16;
  3692.   
  3693.   arrow = XCreateFontCursor (Nlm_currentXDisplay, XC_top_left_arrow);
  3694.   cross = XCreateFontCursor (Nlm_currentXDisplay, XC_cross);
  3695.   iBeam = XCreateFontCursor (Nlm_currentXDisplay, XC_xterm);
  3696.   plus = XCreateFontCursor (Nlm_currentXDisplay, XC_crosshair);
  3697.   watch = XCreateFontCursor (Nlm_currentXDisplay, XC_watch);
  3698.  
  3699.   currentCursor = arrow;
  3700.   
  3701.   font = Nlm_XLoadQueryFont (Nlm_currentXDisplay, "-*-helvetica-bold-r-*--14-*", TRUE);
  3702.   Nlm_XfontList = XmFontListCreate (font, "dummy");
  3703.  
  3704.   Nlm_fileDialogShell = NULL;
  3705.  
  3706.   return TRUE;
  3707. }
  3708. #endif
  3709.  
  3710. static void Nlm_WindowGo (Nlm_WindoW w)
  3711.  
  3712. {
  3713.   inNotice = FALSE;
  3714.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  3715. }
  3716.  
  3717. static void Nlm_PanelGo (Nlm_PaneL p, Nlm_PoinT pt)
  3718.  
  3719. {
  3720.   Nlm_WindoW  w;
  3721.  
  3722.   inNotice = FALSE;
  3723.   w = Nlm_ParentWindow (p);
  3724.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  3725. }
  3726.  
  3727. static void Nlm_CenterLine (Nlm_RectPtr rptr, Nlm_CharPtr text, Nlm_FonT fnt)
  3728.  
  3729. {
  3730.   if (fnt != NULL) {
  3731.     Nlm_SelectFont (fnt);
  3732.   }
  3733.   rptr->bottom = rptr->top + Nlm_LineHeight ();
  3734.   Nlm_DrawString (rptr, text, 'c', FALSE);
  3735.   rptr->top = rptr->bottom;
  3736. }
  3737.  
  3738. static void Nlm_DrawAbout (Nlm_PaneL p)
  3739.  
  3740. {
  3741.   Nlm_RecT  r;
  3742.  
  3743.   Nlm_ObjectRect (p, &r);
  3744.   Nlm_InsetRect (&r, 4, 4);
  3745.   r.top += 10;
  3746.   Nlm_Blue ();
  3747.   Nlm_CenterLine (&r, "VIBRANT", Nlm_systemFont);
  3748.   r.top += 10;
  3749.   Nlm_Red ();
  3750.   Nlm_CenterLine (&r, "National Center for Biotechnology Information", Nlm_systemFont);
  3751.   r.top += 5;
  3752.   Nlm_CenterLine (&r, "National Library of Medicine", Nlm_systemFont);
  3753.   r.top += 5;
  3754.   Nlm_CenterLine (&r, "National Institutes of Health", Nlm_systemFont);
  3755.   r.top += 10;
  3756.   Nlm_CenterLine (&r, "(301) 496-2475", Nlm_systemFont);
  3757.   r.top += 5;
  3758.   Nlm_CenterLine (&r, "info@ncbi.nlm.nih.gov", Nlm_systemFont);
  3759. }
  3760.  
  3761. static void Nlm_GetSet (void)
  3762.  
  3763. {
  3764.   Nlm_PaneL   p;
  3765.   Nlm_WindoW  w;
  3766.  
  3767.   w = Nlm_ModalWindow (-50, -33, -1, -1, Nlm_WindowGo);
  3768.   p = Nlm_SimplePanel (w, 28 * Nlm_stdCharWidth, 10 * Nlm_stdLineHeight, Nlm_DrawAbout);
  3769.   Nlm_SetPanelClick (p, NULL, NULL, NULL, Nlm_PanelGo);
  3770.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  3771.   inNotice = TRUE;
  3772.   while (inNotice) {
  3773.     Nlm_ProcessAnEvent ();
  3774.   }
  3775. }
  3776.  
  3777. static void Nlm_GetReady (void)
  3778.  
  3779. {
  3780. #if defined(COMP_THINKC) || defined(COMP_CODEWAR)
  3781.   KeyMap  keys;
  3782.  
  3783.   GetKeys (keys);
  3784.   if ((keys [1] & 1) != 0) {
  3785.     Nlm_GetSet ();
  3786.   }
  3787. #endif
  3788. #if defined(COMP_MPW)
  3789.   KeyMap  keys;
  3790.  
  3791.   GetKeys (&keys);
  3792.   if ((keys [1] & 1) != 0) {
  3793.     Nlm_GetSet ();
  3794.   }
  3795. #endif
  3796. #ifdef WIN_MAC
  3797.     /* dgg hack for powerpc */
  3798. #if defined(powerc) || defined(__powerc)
  3799.     strcpy( (Nlm_CharPtr)apName+1, "noname"); apName[0]= 6; 
  3800.     apRefNum= 0;
  3801.     apParam= NULL;
  3802.     {
  3803.     OSErr err;
  3804.     ProcessInfoRec info;
  3805.     ProcessSerialNumber  psn;
  3806.     FSSpec     fileSpec;
  3807.     short        wdref = 0;
  3808.  
  3809.     err= GetCurrentProcess( &psn);
  3810.     if ( err == 0 ) {
  3811.         info.processInfoLength = sizeof(ProcessInfoRec);
  3812.         info.processName = (StringPtr) &apName;
  3813.         info.processAppSpec = &fileSpec;
  3814.         err= GetProcessInformation( &psn, &info);
  3815.         if (err == 0) {
  3816.             /* memcpy( apName, info.processName, info.processName[0]); */
  3817.             apRefNum= fileSpec.vRefNum; 
  3818.  
  3819.             /* !! we need the following for apRefNum */
  3820.             err= OpenWD( fileSpec.vRefNum, fileSpec.parID, 0, &wdref);
  3821.             apRefNum= wdref;
  3822.             /* err= CloseWD( wdref); /* ?? */
  3823.             }
  3824.         }
  3825.     }
  3826.  
  3827. #else
  3828.   GetAppParms (apName, &apRefNum, &apParam);
  3829. #endif
  3830.  /* Nlm_PtoCstr ((Nlm_CharPtr) apName); */
  3831. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3832.   p2cstr ((StringPtr) apName);
  3833. #endif
  3834. #ifdef COMP_THINKC
  3835.   PtoCstr ((StringPtr) apName);
  3836. #endif
  3837.  
  3838. #endif
  3839. #ifdef WIN_MSWIN
  3840.   if ((GetAsyncKeyState (VK_SHIFT) & 0x8000) != 0) {
  3841.     Nlm_GetSet ();
  3842.   }
  3843. #endif
  3844. #ifdef WIN_MOTIF
  3845.   argc = statargc;
  3846.   argv = statargv;
  3847. #endif
  3848.   Nlm_ArrowCursor ();
  3849. }
  3850.  
  3851. static void Nlm_CleanUpWindows (void)
  3852.  
  3853. /*
  3854. *  Since submenus goes into the Macintosh desktop menu bar, to allow for
  3855. *  command key equivalents, it can be very dangerous to remove the menu
  3856. *  bar.  The submenu linked into the menu bar now no longer removes its
  3857. *  children, leaving that up to the submenu item.
  3858. */
  3859.  
  3860. {
  3861.   Nlm_GraphiC  g;
  3862.   Nlm_MenuBaR  mb;
  3863.   Nlm_GraphiC  n;
  3864.   Nlm_WindoW   w;
  3865.  
  3866. #ifdef WIN_MSWIN
  3867.   if (timerID != 0) {
  3868.     KillTimer (NULL, timerID);
  3869.   }
  3870. #endif
  3871. #ifdef WIN_MOTIF
  3872.   XtRemoveTimeOut (windowTimer);
  3873. #endif
  3874.   w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) Nlm_desktopWindow);
  3875.   while (w != NULL && w != Nlm_systemWindow) {
  3876.     Nlm_UseWindow (w);
  3877.     Nlm_DoHide ((Nlm_GraphiC) w, TRUE, FALSE);
  3878.     mb = Nlm_GetWindowMenuBar (w);
  3879.     if (mb != NULL) {
  3880.       Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  3881.     }
  3882.     g = Nlm_GetChild ((Nlm_GraphiC) w);
  3883.     while (g != NULL) {
  3884.       n = Nlm_GetNext (g);
  3885.       Nlm_DoRemove (g, FALSE);
  3886.       g = n;
  3887.     }
  3888.     w = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  3889.   }
  3890.   w = Nlm_desktopWindow;
  3891.   mb = Nlm_GetWindowMenuBar (w);
  3892.   if (mb != NULL) {
  3893.     Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  3894.     Nlm_SetWindowMenuBar (w, NULL);
  3895.   }
  3896. }
  3897.  
  3898. #ifdef WIN_MAC
  3899. main ()
  3900.  
  3901. {
  3902.   Nlm_Int2  i;
  3903.  
  3904.   MaxApplZone ();
  3905.   for (i = 0; i < 20; i++) {
  3906.     MoreMasters ();
  3907.   }
  3908.   InitGraf (&qd.thePort);
  3909.   InitFonts ();
  3910.   FlushEvents (everyEvent, 0);
  3911.   InitWindows ();
  3912.   InitMenus ();
  3913.   TEInit ();
  3914.   InitDialogs (0);
  3915.   InitCursor ();
  3916.  
  3917.   Nlm_InitVibrantHooks ();
  3918.  
  3919.   Nlm_InitWindows ();
  3920.   Nlm_InitBars ();
  3921.   Nlm_InitButtons ();
  3922.   Nlm_InitExtras ();
  3923.   Nlm_InitGroup ();
  3924.   Nlm_InitLists ();
  3925.   Nlm_InitMenus ();
  3926.   Nlm_InitPrompt ();
  3927.   Nlm_InitSlate ();
  3928.   Nlm_InitTexts ();
  3929.   Nlm_SetupWindows ();
  3930.   Nlm_RegisterWindows ();
  3931.   Nlm_RegisterTexts ();
  3932.   Nlm_RegisterSlates ();
  3933.   Nlm_GetReady ();
  3934.  
  3935.   Nlm_Main ();
  3936.  
  3937. #ifndef DCLAP
  3938.     /* dgg -- speed up quit; all this cleanup isn't needed */
  3939.   Nlm_CleanUpWindows ();
  3940.   Nlm_CleanUpDrawingTools ();
  3941.   Nlm_FreeWindows ();
  3942.   Nlm_FreeBars ();
  3943.   Nlm_FreeButtons ();
  3944.   Nlm_FreeExtras ();
  3945.   Nlm_FreeGroup ();
  3946.   Nlm_FreeLists ();
  3947.   Nlm_FreeMenus ();
  3948.   Nlm_FreePrompt ();
  3949.   Nlm_FreeSlate ();
  3950.   Nlm_FreeTexts ();
  3951.   Nlm_FreeConfigStruct ();
  3952. #endif
  3953.   ExitToShell ();
  3954.     return 0;
  3955. }
  3956. #endif
  3957.  
  3958. #ifdef WIN_MSWIN
  3959. #ifdef WIN32
  3960. static int Nlm_HandleException (DWORD code)
  3961.  
  3962. {
  3963.   Nlm_Message (MSG_OK, "WIN32 exception %ld", (long) code);
  3964.   return EXCEPTION_CONTINUE_EXECUTION;
  3965. }
  3966. #endif
  3967.  
  3968. int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  3969.                       LPSTR lpszCmdLine, int nCmdShow)
  3970.  
  3971. {
  3972.   Nlm_Char  str [32];
  3973.   WNDCLASS  wc;
  3974.  
  3975. #ifdef WIN32
  3976.   try {
  3977. #endif
  3978.  
  3979.   Nlm_currentHInst = hInstance;
  3980.  
  3981.   Nlm_InitVibrantHooks ();
  3982.  
  3983.   Nlm_InitWindows ();
  3984.   Nlm_InitBars ();
  3985.   Nlm_InitButtons ();
  3986.   Nlm_InitExtras ();
  3987.   Nlm_InitGroup ();
  3988.   Nlm_InitLists ();
  3989.   Nlm_InitMenus ();
  3990.   Nlm_InitPrompt ();
  3991.   Nlm_InitSlate ();
  3992.   Nlm_InitTexts ();
  3993.   Nlm_SetupWindows ();
  3994.   if (! (Nlm_RegisterWindows ())) {
  3995.     return FALSE;
  3996.   }
  3997.   if (! (Nlm_RegisterTexts ())) {
  3998.     return FALSE;
  3999.   }
  4000.   if (! (Nlm_RegisterSlates ())) {
  4001.     sprintf (str, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  4002.     UnregisterClass (str, Nlm_currentHInst);
  4003.     return FALSE;
  4004.   }
  4005.   Nlm_GetReady ();
  4006.  
  4007.   Nlm_Main ();
  4008.  
  4009.   Nlm_CleanUpWindows ();
  4010.   Nlm_CleanUpDrawingTools ();
  4011.   Nlm_FreeWindows ();
  4012.   Nlm_FreeBars ();
  4013.   Nlm_FreeButtons ();
  4014.   Nlm_FreeExtras ();
  4015.   Nlm_FreeGroup ();
  4016.   Nlm_FreeLists ();
  4017.   Nlm_FreeMenus ();
  4018.   Nlm_FreePrompt ();
  4019.   Nlm_FreeSlate ();
  4020.   Nlm_FreeTexts ();
  4021.   Nlm_FreeConfigStruct ();
  4022.  
  4023.   sprintf (str, "Nlm_WindowClass%ld", (long) (int) Nlm_currentHInst);
  4024.   if (GetClassInfo (Nlm_currentHInst, str, &wc)) {
  4025.     DeleteObject (wc.hbrBackground);
  4026.   }
  4027.   UnregisterClass (str, Nlm_currentHInst);
  4028.   sprintf (str, "Nlm_SlateClass%ld", (long) (int) Nlm_currentHInst);
  4029.   UnregisterClass (str, Nlm_currentHInst);
  4030.  
  4031. #ifdef WIN32
  4032.   } except (Nlm_HandleException (GetExceptionCode ())) {
  4033.   }
  4034. #endif
  4035.  
  4036.   return TRUE;
  4037. }
  4038. #endif
  4039.  
  4040. #ifdef WIN_MOTIF
  4041. main (int argc, char *argv [])
  4042.  
  4043. {
  4044.   Nlm_Int2  retval;
  4045.  
  4046.   statargc = argc;
  4047.   statargv = argv;
  4048.  
  4049.   Nlm_InitVibrantHooks ();
  4050.  
  4051.   Nlm_InitWindows ();
  4052.   Nlm_InitButtons ();
  4053.   Nlm_InitExtras ();
  4054.   Nlm_InitGroup ();
  4055.   Nlm_InitBars ();
  4056.   Nlm_InitLists ();
  4057.   Nlm_InitMenus ();
  4058.   Nlm_InitPrompt ();
  4059.   Nlm_InitSlate ();
  4060.   Nlm_InitTexts ();
  4061.   if (! Nlm_SetupWindows ()) {
  4062.     return FALSE;
  4063.   }
  4064.   Nlm_RegisterWindows ();
  4065.   Nlm_RegisterTexts ();
  4066.   Nlm_RegisterSlates ();
  4067.  
  4068. #ifdef NO_GOOD_DCLAP
  4069. /* not doing what we want... */
  4070.     {
  4071.   XtAppContext app_context;
  4072.   Widget toplevel;
  4073.   WidgetClass wclass= applicationShellWidgetClass;
  4074.   char* appclass= "GopherPup";
  4075.   toplevel= XtAppCreateShell( NULL, appclass, wclass, Nlm_currentXDisplay,
  4076.             NULL, 0);
  4077.  
  4078. #if 0
  4079.   toplevel = XtAppInitialize 
  4080.             (NULL/*&app_context*/, appclass, 
  4081.                          NULL, 0, /*options, XtNumber (options),*/
  4082.              &argc, argv, NULL, 
  4083.              NULL, 0); /*Xmx_wargs, Xmx_n);*/
  4084. #endif
  4085.   }
  4086.  
  4087. #endif
  4088.  
  4089.   Nlm_GetReady ();
  4090.   retval = Nlm_Main ();
  4091.  
  4092.   Nlm_CleanUpWindows ();
  4093.   Nlm_CleanUpDrawingTools ();
  4094.   Nlm_FreeWindows ();
  4095.   Nlm_FreeBars ();
  4096.   Nlm_FreeButtons ();
  4097.   Nlm_FreeExtras ();
  4098.   Nlm_FreeGroup ();
  4099.   Nlm_FreeLists ();
  4100.   Nlm_FreeMenus ();
  4101.   Nlm_FreePrompt ();
  4102.   Nlm_FreeSlate ();
  4103.   Nlm_FreeTexts ();
  4104.   Nlm_FreeConfigStruct ();
  4105.   Nlm_currentWindowTool = NULL;
  4106.   Nlm_currentXWindow = 0;
  4107.   Nlm_currentXGC = NULL;
  4108.   if (Nlm_currentXDisplay != NULL) {
  4109.     if (Nlm_fileDialogShell != NULL) {
  4110.       XtDestroyWidget (Nlm_fileDialogShell);
  4111.     }
  4112.     if (Nlm_XfontList != NULL) {
  4113.       XmFontListFree (Nlm_XfontList);
  4114.     }
  4115.     XFreeCursor (Nlm_currentXDisplay, arrow);
  4116.     XFreeCursor (Nlm_currentXDisplay, cross);
  4117.     XFreeCursor (Nlm_currentXDisplay, iBeam);
  4118.     XFreeCursor (Nlm_currentXDisplay, plus);
  4119.     XFreeCursor (Nlm_currentXDisplay, watch);
  4120.     XFreeGC (Nlm_currentXDisplay, firstGC);
  4121.     XCloseDisplay (Nlm_currentXDisplay);
  4122.   }
  4123.   exit (retval);
  4124. }
  4125. #endif
  4126.  
  4127. extern void Nlm_Metronome (Nlm_VoidProc actn)
  4128.  
  4129. {
  4130.   timerAction = actn;
  4131. }
  4132.  
  4133. extern void Nlm_RemoveDyingWindows (void)
  4134.  
  4135. /*
  4136. *  Since submenus goes into the Macintosh desktop menu bar, to allow for
  4137. *  command key equivalents, it can be very dangerous to remove the menu
  4138. *  bar.  The submenu linked into the menu bar now no longer removes its
  4139. *  children, leaving that up to the submenu item.
  4140. */
  4141.  
  4142. {
  4143.   Nlm_GraphiC     g;
  4144.   Nlm_MenuBaR     mb;
  4145.   Nlm_GraphiC     n;
  4146.   Nlm_PortTool    tempPort;
  4147.   Nlm_WindoW      w;
  4148.   Nlm_WindowData  wdata;
  4149.   Nlm_WindowTool  wptr;
  4150. #ifdef WIN_MAC
  4151.   PenState        state;
  4152. #endif
  4153. #ifdef WIN_MOTIF
  4154.   Nlm_ShellTool   shl;
  4155. #endif
  4156.  
  4157.   while (dyingWindow != NULL) {
  4158.     w = dyingWindow;
  4159.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  4160.     Nlm_currentWindowTool = wptr;
  4161. #ifdef WIN_MAC
  4162.     GetPort (&tempPort);
  4163.     GetPenState (&state);
  4164.     SetPort (wptr);
  4165.     Nlm_currentWindowTool = wptr;
  4166.     Nlm_SetUpdateRegion (wptr);
  4167. #endif
  4168. #ifdef WIN_MSWIN
  4169.     tempPort = Nlm_currentHDC;
  4170.     Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  4171. #endif
  4172. #ifdef WIN_MOTIF
  4173.     XSync (Nlm_currentXDisplay, FALSE);
  4174.     Nlm_currentXGC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  4175. #endif
  4176.     mb = Nlm_GetWindowMenuBar (w);
  4177.     if (mb != NULL) {
  4178.       Nlm_DoRemove ((Nlm_GraphiC) mb, FALSE);
  4179.       Nlm_SetWindowMenuBar (w, NULL);
  4180.     }
  4181.     g = Nlm_GetChild ((Nlm_GraphiC) w);
  4182.     while (g != NULL) {
  4183.       n = Nlm_GetNext (g);
  4184.       Nlm_DoRemove (g, FALSE);
  4185.       g = n;
  4186.     }
  4187.     Nlm_ResetDrawingTools ();
  4188.     Nlm_GetWindowData (w, &wdata);
  4189.     if (wdata.data != NULL && wdata.cleanup != NULL) {
  4190.       wdata.cleanup (w, wdata.data);
  4191.     }
  4192. #ifdef WIN_MAC
  4193.     SetPort (tempPort);
  4194.     Nlm_currentWindowTool = tempPort;
  4195.     Nlm_SetUpdateRegion (tempPort);
  4196.     SetPenState (&state);
  4197.     CloseWindow (wptr);
  4198.     Nlm_MemFree (wptr);
  4199. #endif
  4200. #ifdef WIN_MSWIN
  4201.     Nlm_currentHDC = tempPort;
  4202.     RemoveProp (wptr, (LPSTR) "Nlm_VibrantProp");
  4203.     DestroyWindow (wptr);
  4204. #endif
  4205. #ifdef WIN_MOTIF
  4206.     if (wdata.title != NULL) {
  4207.       Nlm_MemFree (wdata.title);
  4208.     }
  4209.     Nlm_currentWindowTool = NULL;
  4210.     Nlm_currentXWindow = 0;
  4211.     Nlm_currentXGC = firstGC;
  4212.     shl = Nlm_GetWindowShell (w);
  4213.     if (NLM_QUIET) {
  4214.       if (Nlm_WindowHasBeenShown (w)) {
  4215.         XtDestroyWidget (shl);
  4216.       }
  4217.     } else {
  4218.       XtDestroyWidget (shl);
  4219.     }
  4220.     XSync (Nlm_currentXDisplay, FALSE);
  4221. #endif
  4222.     dyingWindow = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC) w);
  4223.     Nlm_HandFree (w);
  4224.     recentWindow = NULL;
  4225.     Nlm_Update ();
  4226.   }
  4227. }
  4228.  
  4229. extern void Nlm_Update (void)
  4230.  
  4231. {
  4232. #ifdef WIN_MAC
  4233.   while (EventAvail (updateMask, &Nlm_currentEvent)) {
  4234.     if (WaitNextEvent (updateMask, &Nlm_currentEvent, 0, NULL)) {
  4235.       Nlm_HandleEvent ();
  4236.     }
  4237.   }
  4238. #endif
  4239. #ifdef WIN_MSWIN
  4240.   while (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4241.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4242.       if (Nlm_VibrantDisabled ()) {
  4243.         discard_count++; /* really just a place to set a breakpoint */
  4244.       }
  4245.       TranslateMessage (&Nlm_currentMssg);
  4246.       DispatchMessage (&Nlm_currentMssg);
  4247.     }
  4248.   }
  4249. #endif
  4250. #ifdef WIN_MOTIF
  4251.   XEvent       event;
  4252.   XtInputMask  mask;
  4253.  
  4254.   XSync (Nlm_currentXDisplay, FALSE);
  4255.   mask = XtAppPending (Nlm_appContext);
  4256.   if (mask != 0) {
  4257.     while (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4258.       XtDispatchEvent (&event);
  4259.     }
  4260.   }
  4261.   XSync (Nlm_currentXDisplay, FALSE);
  4262. #endif
  4263. }
  4264.  
  4265. extern void Nlm_KeyboardView (Nlm_KeyProc key)
  4266.  
  4267. {
  4268.   keyAction = key;
  4269. }
  4270.  
  4271. #ifdef WIN_MSWIN
  4272. static void Nlm_ProcessKeyPress (LPMSG lpMsg)
  4273.  
  4274. {
  4275.   Nlm_Char  ch;
  4276.  
  4277.   if (lpMsg->message == WM_CHAR) {
  4278.     ch = (Nlm_Char) lpMsg->wParam;
  4279.     if (keyAction != NULL) {
  4280.       keyAction (ch);
  4281.     }
  4282.   }
  4283. }
  4284. #endif
  4285.  
  4286. #ifdef WIN_MOTIF
  4287. static void Nlm_ProcessKeyPress (XEvent *event)
  4288.  
  4289. {
  4290.   Nlm_Char        buffer [20];
  4291.   Nlm_Char        ch;
  4292.   int             charcount;
  4293.   XComposeStatus  compose;
  4294.   KeySym          keysym;
  4295.  
  4296.   if (event->type == KeyPress) {
  4297.     buffer [0] = '\0';
  4298.     charcount = XLookupString (&(event->xkey), buffer, 20, &keysym, &compose);
  4299.     if (charcount >= 0 && charcount < 20) {
  4300.       buffer [charcount] = '\0';
  4301.     }
  4302.     if (keyAction != NULL) {
  4303.       ch = buffer [0];
  4304.       keyAction (ch);
  4305.     }
  4306.   }
  4307. }
  4308. #endif
  4309.  
  4310. extern void Nlm_ProcessAnEvent (void)
  4311.  
  4312. {
  4313. #ifdef WIN_MAC
  4314.   if (EventAvail (everyEvent, &Nlm_currentEvent)) {
  4315.     if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 0, NULL)) {
  4316.       Nlm_HandleEvent ();
  4317.     }
  4318.   }
  4319. #endif
  4320. #ifdef WIN_MSWIN
  4321.   if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4322.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4323.       TranslateMessage (&Nlm_currentMssg);
  4324.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4325.       DispatchMessage (&Nlm_currentMssg);
  4326.     }
  4327.   }
  4328. #endif
  4329. #ifdef WIN_MOTIF
  4330.   XEvent       event;
  4331.   XtInputMask  mask;
  4332.  
  4333.   mask = XtAppPending (Nlm_appContext);
  4334.   if (mask != 0) {
  4335.     XtAppNextEvent (Nlm_appContext, &event);
  4336.     Nlm_ProcessKeyPress (&event);
  4337.     XtDispatchEvent (&event);
  4338.   }
  4339. #endif
  4340. }
  4341.  
  4342. extern void Nlm_ProcessTimerEvent (void)
  4343.  
  4344. {
  4345. #ifdef WIN_MAC
  4346.   Nlm_Int4  delta;
  4347.   Nlm_Int4  ticks;
  4348.  
  4349.   ticks = Nlm_ComputerTime ();
  4350.   delta = ticks - lastTimerTime;
  4351.   if (delta >= 3) {
  4352.     lastTimerTime = ticks;
  4353.     if (timerAction != NULL) {
  4354.       timerAction ();
  4355.     }
  4356.   }
  4357. #endif
  4358. }
  4359.  
  4360. #ifdef WIN_MAC
  4361. static void Nlm_ProcessIdle (void)
  4362.  
  4363. {
  4364.   Nlm_PointTool  ptool;
  4365.  
  4366.   Nlm_ProcessTimerEvent ();
  4367.   GetMouse (&ptool);
  4368.   LocalToGlobal (&ptool);
  4369.   Nlm_PointToolToPoinT (ptool, &Nlm_globalMouse);
  4370.   frontWindow = Nlm_FindWindowRec (FrontWindow ());
  4371.   Nlm_DoIdle ((Nlm_GraphiC) frontWindow, Nlm_globalMouse);
  4372.   Nlm_ClearKeys ();
  4373. }
  4374. #endif
  4375.  
  4376. extern void Nlm_ProcessEventOrIdle (void)
  4377.  
  4378. {
  4379. #ifdef WIN_MAC
  4380.   if (EventAvail (everyEvent, &Nlm_currentEvent)) {
  4381.     if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 0, NULL)) {
  4382.       Nlm_HandleEvent ();
  4383.     }
  4384.   } else {
  4385.     Nlm_ProcessIdle ();
  4386.   }
  4387. #endif
  4388. #ifdef WIN_MSWIN
  4389.   if (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4390.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4391.       TranslateMessage (&Nlm_currentMssg);
  4392.       DispatchMessage (&Nlm_currentMssg);
  4393.     }
  4394.   } else if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4395.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4396.       TranslateMessage (&Nlm_currentMssg);
  4397.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4398.       DispatchMessage (&Nlm_currentMssg);
  4399.     }
  4400.   }
  4401. #endif
  4402. #ifdef WIN_MOTIF
  4403.   XEvent       event;
  4404.   XtInputMask  mask;
  4405.  
  4406.   mask = XtAppPending (Nlm_appContext);
  4407.   if (mask != 0) {
  4408.     if (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4409.       XtDispatchEvent (&event);
  4410.     } else {
  4411.       XtAppNextEvent (Nlm_appContext, &event);
  4412.       Nlm_ProcessKeyPress (&event);
  4413.       XtDispatchEvent (&event);
  4414.     }
  4415.   }
  4416. #endif
  4417. }
  4418.  
  4419.  
  4420.  
  4421. extern void Nlm_ProcessExternalEvent (void)
  4422.  
  4423. {
  4424. #ifdef WIN_MAC
  4425.   if (WaitNextEvent (everyEvent, &Nlm_currentEvent, 10, NULL)) {
  4426.     Nlm_HandleEvent ();
  4427.   }
  4428. #endif
  4429. #ifdef WIN_MSWIN
  4430.   if (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4431.     if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4432.       TranslateMessage (&Nlm_currentMssg);
  4433.       DispatchMessage (&Nlm_currentMssg);
  4434.     }
  4435.   } else if (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE)) {
  4436.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4437.       TranslateMessage (&Nlm_currentMssg);
  4438.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4439.       DispatchMessage (&Nlm_currentMssg);
  4440.     }
  4441.   }
  4442. #endif
  4443. #ifdef WIN_MOTIF
  4444.   XEvent       event;
  4445.   XtInputMask  mask;
  4446.  
  4447.   mask = XtAppPending (Nlm_appContext);
  4448.   if (mask != 0) {
  4449.     if (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4450.       XtDispatchEvent (&event);
  4451.     } else {
  4452.       XtAppNextEvent (Nlm_appContext, &event);
  4453.       Nlm_ProcessKeyPress (&event);
  4454.       XtDispatchEvent (&event);
  4455.     }
  4456.   }
  4457. #endif
  4458. }
  4459.  
  4460. extern void Nlm_ProcessEvents (void)
  4461.  
  4462. {
  4463. #ifdef WIN_MAC
  4464.   while (! quitProgram) {
  4465.     if (! EventAvail (everyEvent, &Nlm_currentEvent)) {
  4466.       Nlm_ProcessIdle ();
  4467.     }
  4468.     while (WaitNextEvent (everyEvent, &Nlm_currentEvent, 1, NULL)) {
  4469.       Nlm_HandleEvent ();
  4470.       Nlm_RemoveDyingWindows ();
  4471.     }
  4472.   }
  4473. #endif
  4474. #ifdef WIN_MSWIN
  4475.   while (! quitProgram) {
  4476.     while (PeekMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT, PM_NOREMOVE)) {
  4477.       if (GetMessage (&Nlm_currentMssg, NULL, WM_PAINT, WM_PAINT)) {
  4478.         TranslateMessage (&Nlm_currentMssg);
  4479.         DispatchMessage (&Nlm_currentMssg);
  4480.       }
  4481.     }
  4482.     if (GetMessage (&Nlm_currentMssg, NULL, 0, 0)) {
  4483.       TranslateMessage (&Nlm_currentMssg);
  4484.       Nlm_ProcessKeyPress (&Nlm_currentMssg);
  4485.       DispatchMessage (&Nlm_currentMssg);
  4486.       Nlm_RemoveDyingWindows ();
  4487.     }
  4488.   }
  4489. #endif
  4490. #ifdef WIN_MOTIF
  4491.   XEvent       event;
  4492.   XtInputMask  mask;
  4493.  
  4494.   while (! quitProgram) {
  4495.     mask = XtAppPending (Nlm_appContext);
  4496.     if (mask != 0) {
  4497.       while (XCheckTypedEvent (Nlm_currentXDisplay, Expose, &event)) {
  4498.         XtDispatchEvent (&event);
  4499.       }
  4500.     }
  4501.     XtAppNextEvent (Nlm_appContext, &event);
  4502.     Nlm_ProcessKeyPress (&event);
  4503.     XtDispatchEvent (&event);
  4504.     Nlm_RemoveDyingWindows ();
  4505.   }
  4506.   if (Nlm_currentXDisplay != NULL) {
  4507.     XSync (Nlm_currentXDisplay, TRUE);
  4508.   }
  4509. #endif
  4510.   Nlm_RemoveDyingWindows ();
  4511. }
  4512.  
  4513. extern Nlm_Boolean Nlm_EventAvail (void)
  4514.  
  4515. {
  4516. #ifdef WIN_MAC
  4517.   return (EventAvail (everyEvent, &Nlm_currentEvent));
  4518. #endif
  4519. #ifdef WIN_MSWIN
  4520.   return (Nlm_Boolean) (PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD));
  4521. #endif
  4522. #ifdef WIN_MOTIF
  4523.   return (XtAppPending (Nlm_appContext) != 0);
  4524. #endif
  4525. }
  4526.  
  4527. extern void Nlm_FlushEvents (void)
  4528.  
  4529. {
  4530. #ifdef WIN_MAC
  4531.   FlushEvents (everyEvent - updateMask, 0);
  4532. #endif
  4533. #ifdef WIN_MSWIN
  4534.   Nlm_Boolean  goOn;
  4535.  
  4536.   goOn = TRUE;
  4537.   while (goOn) {
  4538.     goOn = (Nlm_Boolean) PeekMessage (&Nlm_currentMssg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD);
  4539.     if (goOn && Nlm_currentMssg.message == WM_PAINT) {
  4540.       goOn = FALSE;
  4541.     }
  4542.   }
  4543. #endif
  4544. #ifdef WIN_MOTIF
  4545.   if (Nlm_currentXDisplay != NULL) {
  4546.     XSync (Nlm_currentXDisplay, FALSE);
  4547.   }
  4548. #endif
  4549. }
  4550.  
  4551. extern void Nlm_QuitProgram (void)
  4552.  
  4553. {
  4554.   quitProgram = TRUE;
  4555. #ifdef WIN_MSWIN
  4556.   PostQuitMessage (0);
  4557. #endif
  4558. }
  4559.  
  4560. extern void Nlm_UnloadSegment (Nlm_VoidProc routineAddr)
  4561.  
  4562. {
  4563. #ifdef WIN_MAC
  4564.   if (routineAddr != NULL) {
  4565.     UnloadSeg ((void *) routineAddr);
  4566.   }
  4567. #endif
  4568. }
  4569.  
  4570. static void Nlm_GetArgsOkProc (Nlm_ButtoN b)
  4571.  
  4572. {
  4573.   getArgsBoxUp = FALSE;
  4574.   getArgsOk = TRUE;
  4575. }
  4576.  
  4577. static void Nlm_GetArgsCancelProc (Nlm_ButtoN b)
  4578.  
  4579. {
  4580.   getArgsBoxUp = FALSE;
  4581. }
  4582.  
  4583. static Nlm_GraphiC Nlm_GetPrevObject (Nlm_GraphiC g)
  4584.  
  4585. {
  4586.   Nlm_GraphiC  prev;
  4587.   Nlm_GraphiC  prnt;
  4588.   Nlm_GraphiC  thisitem;
  4589.  
  4590.   prev = NULL;
  4591.   if (g != NULL) {
  4592.     prnt = Nlm_GetParent (g);
  4593.     thisitem = Nlm_GetChild (prnt);
  4594.     while (thisitem != NULL && thisitem != g) {
  4595.       prev = thisitem;
  4596.       thisitem = Nlm_GetNext (thisitem);
  4597.     }
  4598.   }
  4599.   return prev;
  4600. }
  4601.  
  4602. static void Nlm_GetArgsFileInProc (Nlm_ButtoN b)
  4603.  
  4604. {
  4605.   Nlm_Char  path [PATH_MAX];
  4606.   Nlm_TexT  t;
  4607.  
  4608.   t = (Nlm_TexT) Nlm_GetPrevObject ((Nlm_GraphiC) b);
  4609.   if (t != NULL) {
  4610.     if (Nlm_GetInputFileName (path, sizeof (path), "", "TEXT")) {
  4611.       Nlm_SetTitle ((Nlm_Handle) t, path);
  4612.     }
  4613.   }
  4614. }
  4615.  
  4616. static void Nlm_GetArgsFileOutProc (Nlm_ButtoN b)
  4617.  
  4618. {
  4619.   Nlm_Char  path [PATH_MAX];
  4620.   Nlm_TexT  t;
  4621.  
  4622.   t = (Nlm_TexT) Nlm_GetPrevObject ((Nlm_GraphiC) b);
  4623.   if (t != NULL) {
  4624.     if (Nlm_GetOutputFileName (path, sizeof (path), "")) {
  4625.       Nlm_SetTitle ((Nlm_Handle) t, path);
  4626.     }
  4627.   }
  4628. }
  4629.  
  4630. #define MAX_ARGS 50
  4631.  
  4632. typedef Nlm_Handle PNTR Nlm_HandlePtr;
  4633.  
  4634. extern Nlm_Boolean Nlm_GetArgs (Nlm_CharPtr progname, Nlm_Int2 numargs, Nlm_ArgPtr ap)
  4635.  
  4636. {
  4637.   static char * TypeStrings[9] = {
  4638.         "",
  4639.         "Integer: ",
  4640.         "Float: ",
  4641.         "String: ",
  4642.         "File In: ",
  4643.         "File Out: ",
  4644.         "Data In: ",
  4645.         "Data Out: " };
  4646.   Nlm_Boolean    okay = FALSE;
  4647.   Nlm_Boolean    range;
  4648.   Nlm_Int2       i;
  4649.   Nlm_Int2       j;
  4650.   Nlm_Int4       ifrom, ito;
  4651.   Nlm_FloatHi    ffrom, fto;
  4652.   Nlm_ArgPtr     curarg;
  4653.   Nlm_Boolean    resolved [MAX_ARGS];
  4654.   Nlm_Char       arg [80];
  4655.   Nlm_CharPtr    buf;
  4656.   Nlm_Char       ch;
  4657.   Nlm_Int2       delta;
  4658.   Nlm_GrouP      g;
  4659.   Nlm_GrouP      h;
  4660.   Nlm_HandlePtr  hp;
  4661.   Nlm_Int2       k;
  4662.   Nlm_Int2       l;
  4663.   Nlm_GrouP      pg;
  4664.   Nlm_RecT       r1;
  4665.   Nlm_RecT       r2;
  4666.   Nlm_Boolean    smallScreen;
  4667.   Nlm_WindoW     w;
  4668.   Nlm_TexT       firstText;
  4669.   Nlm_CharPtr    tmp;
  4670.  
  4671.   if ((ap == NULL) || (numargs == 0) || (numargs > MAX_ARGS)) {
  4672.     return okay;
  4673.   }
  4674.  
  4675.   curarg = ap;
  4676.   Nlm_MemFill (resolved, '\0', (MAX_ARGS * sizeof(Nlm_Boolean)));
  4677.  
  4678.   for (i = 0; i < numargs; i++, curarg++) {
  4679.     if ((curarg->type < ARG_BOOLEAN) || (curarg->type > ARG_DATA_OUT)) {
  4680.       Message(MSG_ERROR, "Invalid Arg->type in %s", curarg->prompt);
  4681.       return okay;
  4682.     }
  4683.     curarg->intvalue = 0;
  4684.     curarg->floatvalue = 0.0;
  4685.     curarg->strvalue = NULL;
  4686.     if (curarg->defaultvalue != NULL) {
  4687.       resolved [i] = TRUE;
  4688.       switch (curarg->type) {
  4689.         case ARG_BOOLEAN:
  4690.           if (TO_UPPER(*curarg->defaultvalue) == 'T') {
  4691.             curarg->intvalue = 1;
  4692.           } else {
  4693.             curarg->intvalue = 0;
  4694.           }
  4695.           break;
  4696.         case ARG_INT:
  4697.           sscanf(curarg->defaultvalue, "%ld", &curarg->intvalue);
  4698.           break;
  4699.         case ARG_FLOAT:
  4700.           sscanf(curarg->defaultvalue, "%lf", &curarg->floatvalue);
  4701.           break;
  4702.         case ARG_STRING:
  4703.         case ARG_FILE_IN:
  4704.         case ARG_FILE_OUT:
  4705.         case ARG_DATA_IN:
  4706.         case ARG_DATA_OUT:
  4707.           curarg->strvalue = StringSave (curarg->defaultvalue);
  4708.           break;
  4709.       }
  4710.     }
  4711.   }
  4712.  
  4713.   Nlm_StringMove(arg, progname);
  4714.   w = Nlm_FixedWindow (-50, -33, -10, -10, arg, NULL);
  4715.   smallScreen = FALSE;
  4716. #ifdef WIN_MAC
  4717.   if (Nlm_screenRect.right < 513 || Nlm_screenRect.bottom < 343) {
  4718.     smallScreen = TRUE;
  4719.   }
  4720. #endif
  4721. #ifdef WIN_MSWIN
  4722.   if (Nlm_screenRect.bottom < 352) {
  4723.     smallScreen = TRUE;
  4724.   }
  4725. #endif
  4726.   g = Nlm_HiddenGroup (w, 4, 0, NULL);
  4727.   hp = (Nlm_HandlePtr) Nlm_MemNew (numargs * sizeof (Nlm_Handle));
  4728.  
  4729.   firstText = NULL;
  4730.   curarg = ap;
  4731.   for (i = 0, j = 0; i < numargs; i++, j++, curarg++) {
  4732.     if ((smallScreen && j >= 10) || j >= 15) {
  4733.       j = 0;
  4734.       Nlm_Advance (w);
  4735.       g = Nlm_HiddenGroup (w, 4, 0, NULL);
  4736.     }
  4737.     Nlm_StaticPrompt (g, TypeStrings[curarg->type - 1], 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4738.     switch (curarg->type) {
  4739.       case ARG_BOOLEAN:
  4740.         hp [i] = (Nlm_Handle) Nlm_CheckBox (g, curarg->prompt, NULL);
  4741.         Nlm_StaticPrompt (g, "", 0, 0, Nlm_systemFont, 'l');
  4742.         if (curarg->intvalue == 1) {
  4743.           Nlm_SetStatus (hp [i], TRUE);
  4744.         }
  4745.         break;
  4746.       case ARG_INT:
  4747.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4748.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4749.         if (firstText == NULL) {
  4750.           firstText = (Nlm_TexT) hp [i];
  4751.         }
  4752.         break;
  4753.       case ARG_FLOAT:
  4754.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4755.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4756.         if (firstText == NULL) {
  4757.           firstText = (Nlm_TexT) hp [i];
  4758.         }
  4759.         break;
  4760.       case ARG_STRING:
  4761.         pg = Nlm_HiddenGroup (g, 0, 10, NULL);
  4762.         Nlm_SetGroupMargins (pg, 1, 1);
  4763.         Nlm_SetGroupSpacing (pg, 1, 1);
  4764.         buf = curarg->prompt;
  4765.         k = 0;
  4766.         while (Nlm_StringLen (buf + k) > 0) {
  4767.           l = 0;
  4768.           ch = buf [k + l];
  4769.           while (ch != '\0' && ch != '\n' && ch != '\r') {
  4770.             l++;
  4771.             ch = buf [k + l];
  4772.           }
  4773.           if (ch == '\n' || ch == '\r') {
  4774.             buf [k + l] = '\0';
  4775.             if (Nlm_StringLen (buf + k) > 0) {
  4776.               Nlm_StaticPrompt (pg, buf + k, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4777.             }
  4778.             k += l + 1;
  4779.           } else {
  4780.             if (Nlm_StringLen (buf + k) > 0) {
  4781.               Nlm_StaticPrompt (pg, buf + k, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4782.             }
  4783.             k += l;
  4784.           }
  4785.         }
  4786.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4787.         if (firstText == NULL) {
  4788.           firstText = (Nlm_TexT) hp [i];
  4789.         }
  4790.         break;
  4791.       case ARG_FILE_IN:
  4792.       case ARG_FILE_OUT:
  4793.       case ARG_DATA_IN:
  4794.       case ARG_DATA_OUT:
  4795.         Nlm_StaticPrompt (g, curarg->prompt, 0, Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4796.         hp [i] = (Nlm_Handle) Nlm_DialogText (g, curarg->defaultvalue, 10, NULL);
  4797.         if (firstText == NULL) {
  4798.           firstText = (Nlm_TexT) hp [i];
  4799.         }
  4800.         break;
  4801.     }
  4802.     arg[0] = '\0';
  4803.     if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4804.       tmp = Nlm_StringMove(arg, " (");
  4805.       tmp = Nlm_StringMove(tmp, curarg->from);
  4806.       if ((curarg->type == ARG_INT) || (curarg->type == ARG_FLOAT)) {
  4807.         tmp = Nlm_StringMove(tmp, " to ");
  4808.         tmp = Nlm_StringMove(tmp, curarg->to);
  4809.       }
  4810.       Nlm_StringMove(tmp, ")");
  4811.     } else {
  4812.       arg[0] = '\0';
  4813.     }
  4814.     if (curarg->type == ARG_FILE_IN) {
  4815.       Nlm_PushButton (g, "File IN", Nlm_GetArgsFileInProc);
  4816.     } else if (curarg->type == ARG_FILE_OUT) {
  4817.       Nlm_PushButton (g, "File OUT", Nlm_GetArgsFileOutProc);
  4818.     } else {
  4819.       Nlm_StaticPrompt(g, arg, 0,  Nlm_dialogTextHeight, Nlm_systemFont, 'l');
  4820.     }
  4821.   }
  4822.  
  4823.   Nlm_Break (w);
  4824.   h = Nlm_HiddenGroup (w, 10, 0, NULL);
  4825.   Nlm_PushButton (h, "OK", Nlm_GetArgsOkProc);
  4826.   Nlm_PushButton (h, "Cancel", Nlm_GetArgsCancelProc);
  4827.   Nlm_GetRect ((Nlm_GraphiC) g, &r1);
  4828.   Nlm_DoGetPosition ((Nlm_GraphiC) h, &r2);
  4829.   delta = (r1.right - r2.right);
  4830.   if (delta > 0) {
  4831.     Nlm_OffsetRect (&r2, delta / 2, 0);
  4832.     Nlm_DoSetPosition ((Nlm_GraphiC) h, &r2, TRUE);
  4833.   }
  4834.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  4835.   if (firstText != NULL) {
  4836.     Nlm_DoSelect ((Nlm_GraphiC) firstText, TRUE);
  4837.   }
  4838.   getArgsBoxUp = TRUE;
  4839.   while (getArgsBoxUp) {
  4840.     getArgsOk = FALSE;
  4841.     while (getArgsBoxUp) {
  4842.       Nlm_ProcessEventOrIdle ();
  4843.     }
  4844.  
  4845.     if (getArgsOk) {
  4846.       curarg = ap;
  4847.       for (i = 0; ((i < numargs) && (getArgsBoxUp == FALSE)); i++, curarg++) {
  4848.         resolved [i] = TRUE;
  4849.         switch (curarg->type) {
  4850.           case ARG_BOOLEAN:
  4851.             if (Nlm_GetStatus (hp [i])) {
  4852.               curarg->intvalue = 1;
  4853.             } else {
  4854.               curarg->intvalue = 0;
  4855.             }
  4856.             break;
  4857.           case ARG_INT:
  4858.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4859.             sscanf(arg, "%ld", &curarg->intvalue);
  4860.             if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4861.               range = TRUE;
  4862.               if (curarg->from != NULL) {
  4863.                 sscanf(curarg->from, "%ld", &ifrom);
  4864.                 if (curarg->intvalue < ifrom) {
  4865.                   range = FALSE;
  4866.                 }
  4867.               }
  4868.               if (curarg->to != NULL) {
  4869.                 sscanf(curarg->to, "%ld", &ito);
  4870.                 if (curarg->intvalue > ito) {
  4871.                   range = FALSE;
  4872.                 }
  4873.               }
  4874.               if (! range) {
  4875.                 if (curarg->from != NULL && curarg->to != NULL) {
  4876.                   Message(MSG_ERROR, "%s [%ld] is out of range [%ld to %ld]",
  4877.                           curarg->prompt, curarg->intvalue, ifrom, ito);
  4878.                 } else if (curarg->from != NULL) {
  4879.                   Message(MSG_ERROR, "%s [%ld] is out of range [%ld to ...]",
  4880.                           curarg->prompt, curarg->intvalue, ifrom);
  4881.                 } else if (curarg->to != NULL) {
  4882.                   Message(MSG_ERROR, "%s [%ld] is out of range [... to %ld]",
  4883.                           curarg->prompt, curarg->intvalue, ito);
  4884.                 }
  4885.                 getArgsBoxUp = TRUE;
  4886.                 Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  4887.               }
  4888.             }
  4889.             break;
  4890.           case ARG_FLOAT:
  4891.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4892.             sscanf(arg, "%lf", &curarg->floatvalue);
  4893.             if ((curarg->from != NULL) || (curarg->to != NULL)) {
  4894.               range = TRUE;
  4895.               if (curarg->from != NULL) {
  4896.                 sscanf(curarg->from, "%lf", &ffrom);
  4897.                 if (curarg->floatvalue < ffrom) {
  4898.                   range = FALSE;
  4899.                 }
  4900.               }
  4901.               if (curarg->to != NULL) {
  4902.                 sscanf(curarg->to, "%lf", &fto);
  4903.                 if (curarg->floatvalue > fto) {
  4904.                   range = FALSE;
  4905.                 }
  4906.               }
  4907.               if (! range) {
  4908.                 if (curarg->from != NULL && curarg->to != NULL) {
  4909.                   Message(MSG_ERROR, "%s [%g] is out of range [%g to %g]",
  4910.                           curarg->prompt, curarg->floatvalue, ffrom, fto);
  4911.                 } else if (curarg->from != NULL) {
  4912.                   Message(MSG_ERROR, "%s [%g] is out of range [%g to ...]",
  4913.                           curarg->prompt, curarg->floatvalue, ffrom);
  4914.                 } else if (curarg->to != NULL) {
  4915.                   Message(MSG_ERROR, "%s [%g] is out of range [... to %g]",
  4916.                           curarg->prompt, curarg->floatvalue, fto);
  4917.                 }
  4918.                 Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  4919.                 getArgsBoxUp = TRUE;
  4920.               }
  4921.             }
  4922.             break;
  4923.           case ARG_STRING:
  4924.           case ARG_FILE_IN:
  4925.           case ARG_FILE_OUT:
  4926.           case ARG_DATA_IN:
  4927.           case ARG_DATA_OUT:
  4928.             Nlm_GetTitle (hp [i], arg, sizeof (arg));
  4929.             if (arg [0] != '\0') {
  4930.               curarg->strvalue = StringSave (arg);
  4931.             } else {
  4932.               curarg->strvalue = NULL;
  4933.             }
  4934.             break;
  4935.         }
  4936.       }
  4937.  
  4938.       curarg = ap;
  4939.       if (! getArgsBoxUp) {
  4940.         for (i = 0; i < numargs; i++, curarg++) {
  4941.           if ((! curarg->optional) && (! resolved[i])) {
  4942.             Message(MSG_ERROR, "%s was not given an argument", curarg->prompt);
  4943.             getArgsBoxUp = TRUE;
  4944.             Nlm_DoSelect ((Nlm_GraphiC) hp[i], TRUE);
  4945.             break;
  4946.           }
  4947.         }
  4948.       }
  4949.     }
  4950.   }  
  4951.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  4952.   Nlm_Update ();
  4953.  
  4954.   if (getArgsOk) {  /* leave up a little window with the program name */
  4955.     Nlm_StringMove(arg, progname);
  4956.     w = Nlm_FixedWindow (-50, -33, -10, -10, arg, NULL);
  4957.     Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  4958.   }
  4959.   return getArgsOk;
  4960. }
  4961.  
  4962. extern void Nlm_FreeWindows (void)
  4963.  
  4964. {
  4965.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  4966. }
  4967.  
  4968. extern void Nlm_InitWindows (void)
  4969.  
  4970. {
  4971.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 11);
  4972.  
  4973.   documentProcs = &(gphprcsptr [0]);
  4974. #ifdef WIN_MAC
  4975.   documentProcs->click = Nlm_DocumentClick;
  4976.   documentProcs->key = Nlm_NormalKey;
  4977.   documentProcs->draw = Nlm_DocumentDraw;
  4978.   documentProcs->idle = Nlm_NormalIdle;
  4979. #endif
  4980.   documentProcs->show = Nlm_ShowDocument;
  4981.   documentProcs->hide = Nlm_HideWindow;
  4982.   documentProcs->activate = Nlm_DocumentActivate;
  4983.   documentProcs->deactivate = Nlm_DocumentDeactivate;
  4984.   documentProcs->remove = Nlm_RemoveWindow;
  4985.   documentProcs->select = Nlm_NormalSelect;
  4986.   documentProcs->linkIn = Nlm_LinkIn;
  4987.   documentProcs->adjustPrnt = Nlm_AdjustWindow;
  4988.   documentProcs->setTitle = Nlm_SetWindowTitle;
  4989.   documentProcs->getTitle = Nlm_GetWindowTitle;
  4990.   documentProcs->gainFocus = Nlm_WindowGainFocus;
  4991.   documentProcs->loseFocus = Nlm_WindowLoseFocus;
  4992.   documentProcs->sendChar = Nlm_NormalDrawChar;
  4993.  
  4994.   fixedProcs = &(gphprcsptr [1]);
  4995. #ifdef WIN_MAC
  4996.   fixedProcs->click = Nlm_DialogClick;
  4997.   fixedProcs->key = Nlm_NormalKey;
  4998.   fixedProcs->draw = Nlm_NormalDraw;
  4999.   fixedProcs->idle = Nlm_NormalIdle;
  5000. #endif
  5001.   fixedProcs->show = Nlm_ShowNormal;
  5002.   fixedProcs->hide = Nlm_HideWindow;
  5003.   fixedProcs->activate = Nlm_NormalActivate;
  5004.   fixedProcs->deactivate = Nlm_NormalDeactivate;
  5005.   fixedProcs->remove = Nlm_RemoveWindow;
  5006.   fixedProcs->select = Nlm_NormalSelect;
  5007.   fixedProcs->countItems = NULL;
  5008.   fixedProcs->linkIn = Nlm_LinkIn;
  5009.   fixedProcs->adjustPrnt = Nlm_AdjustWindow;
  5010.   fixedProcs->setTitle = Nlm_SetWindowTitle;
  5011.   fixedProcs->getTitle = Nlm_GetWindowTitle;
  5012.   fixedProcs->gainFocus = Nlm_WindowGainFocus;
  5013.   fixedProcs->loseFocus = Nlm_WindowLoseFocus;
  5014.   fixedProcs->sendChar = Nlm_NormalDrawChar;
  5015.  
  5016.   frozenProcs = &(gphprcsptr [2]);
  5017. #ifdef WIN_MAC
  5018.   frozenProcs->click = Nlm_FrozenClick;
  5019.   frozenProcs->key = Nlm_NormalKey;
  5020.   frozenProcs->draw = Nlm_NormalDraw;
  5021.   frozenProcs->idle = Nlm_NormalIdle;
  5022. #endif
  5023.   frozenProcs->show = Nlm_ShowNormal;
  5024.   frozenProcs->hide = Nlm_HideWindow;
  5025.   frozenProcs->activate = Nlm_NormalActivate;
  5026.   frozenProcs->deactivate = Nlm_NormalDeactivate;
  5027.   frozenProcs->remove = Nlm_RemoveWindow;
  5028.   frozenProcs->select = Nlm_NormalSelect;
  5029.   frozenProcs->linkIn = Nlm_LinkIn;
  5030.   frozenProcs->adjustPrnt = Nlm_AdjustWindow;
  5031.   frozenProcs->setTitle = Nlm_SetWindowTitle;
  5032.   frozenProcs->getTitle = Nlm_GetWindowTitle;
  5033.   frozenProcs->gainFocus = Nlm_WindowGainFocus;
  5034.   frozenProcs->loseFocus = Nlm_WindowLoseFocus;
  5035.   frozenProcs->sendChar = Nlm_NormalDrawChar;
  5036.  
  5037.   roundProcs = &(gphprcsptr [3]);
  5038. #ifdef WIN_MAC
  5039.   roundProcs->click = Nlm_DialogClick;
  5040.   roundProcs->key = Nlm_NormalKey;
  5041.   roundProcs->draw = Nlm_NormalDraw;
  5042.   roundProcs->idle = Nlm_NormalIdle;
  5043. #endif
  5044.   roundProcs->show = Nlm_ShowNormal;
  5045.   roundProcs->hide = Nlm_HideWindow;
  5046.   roundProcs->activate = Nlm_NormalActivate;
  5047.   roundProcs->deactivate = Nlm_NormalDeactivate;
  5048.   roundProcs->remove = Nlm_RemoveWindow;
  5049.   roundProcs->select = Nlm_NormalSelect;
  5050.   roundProcs->linkIn = Nlm_LinkIn;
  5051.   roundProcs->adjustPrnt = Nlm_AdjustWindow;
  5052.   roundProcs->setTitle = Nlm_SetWindowTitle;
  5053.   roundProcs->getTitle = Nlm_GetWindowTitle;
  5054.   roundProcs->gainFocus = Nlm_WindowGainFocus;
  5055.   roundProcs->loseFocus = Nlm_WindowLoseFocus;
  5056.   roundProcs->sendChar = Nlm_NormalDrawChar;
  5057.  
  5058.   alertProcs = &(gphprcsptr [4]);
  5059. #ifdef WIN_MAC
  5060.   alertProcs->click = Nlm_PlainClick;
  5061.   alertProcs->key = Nlm_NormalKey;
  5062.   alertProcs->draw = Nlm_NormalDraw;
  5063.   alertProcs->idle = Nlm_NormalIdle;
  5064. #endif
  5065.   alertProcs->show = Nlm_ShowNormal;
  5066.   alertProcs->hide = Nlm_HideWindow;
  5067.   alertProcs->activate = Nlm_NormalActivate;
  5068.   alertProcs->deactivate = Nlm_NormalDeactivate;
  5069.   alertProcs->remove = Nlm_RemoveWindow;
  5070.   alertProcs->select = Nlm_PlainSelect;
  5071.   alertProcs->linkIn = Nlm_LinkIn;
  5072.   alertProcs->adjustPrnt = Nlm_AdjustWindow;
  5073.   alertProcs->setTitle = Nlm_SetWindowTitle;
  5074.   alertProcs->getTitle = Nlm_GetWindowTitle;
  5075.   alertProcs->gainFocus = Nlm_WindowGainFocus;
  5076.   alertProcs->loseFocus = Nlm_WindowLoseFocus;
  5077.   alertProcs->sendChar = Nlm_NormalDrawChar;
  5078.  
  5079.   modalProcs = &(gphprcsptr [5]);
  5080. #ifdef WIN_MAC
  5081.   modalProcs->click = Nlm_ModalClick;
  5082.   modalProcs->key = Nlm_ModalKey;
  5083.   modalProcs->draw = Nlm_NormalDraw;
  5084.   modalProcs->idle = Nlm_NormalIdle;
  5085. #endif
  5086.   modalProcs->show = Nlm_ShowModal;
  5087.   modalProcs->hide = Nlm_HideModal;
  5088.   modalProcs->activate = Nlm_NormalActivate;
  5089.   modalProcs->deactivate = Nlm_NormalDeactivate;
  5090.   modalProcs->remove = Nlm_RemoveWindow;
  5091.   modalProcs->select = Nlm_PlainSelect;
  5092.   modalProcs->linkIn = Nlm_LinkIn;
  5093.   modalProcs->adjustPrnt = Nlm_AdjustWindow;
  5094.   modalProcs->setTitle = Nlm_SetWindowTitle;
  5095.   modalProcs->getTitle = Nlm_GetWindowTitle;
  5096.   modalProcs->gainFocus = Nlm_WindowGainFocus;
  5097.   modalProcs->loseFocus = Nlm_WindowLoseFocus;
  5098.   modalProcs->sendChar = Nlm_NormalDrawChar;
  5099.  
  5100.   floatingProcs = &(gphprcsptr [6]);
  5101. #ifdef WIN_MAC
  5102.   floatingProcs->click = Nlm_FloatingClick;
  5103.   floatingProcs->key = Nlm_FloatingKey;
  5104.   floatingProcs->draw = Nlm_NormalDraw;
  5105.   floatingProcs->idle = Nlm_FloatingIdle;
  5106. #endif
  5107.   floatingProcs->show = Nlm_ShowNormal;
  5108.   floatingProcs->hide = Nlm_HideWindow;
  5109.   floatingProcs->activate = Nlm_NormalActivate;
  5110.   floatingProcs->deactivate = Nlm_NormalDeactivate;
  5111.   floatingProcs->remove = Nlm_RemoveWindow;
  5112.   floatingProcs->select = Nlm_FloatingSelect;
  5113.   floatingProcs->linkIn = Nlm_LinkIn;
  5114.   floatingProcs->adjustPrnt = Nlm_AdjustWindow;
  5115.   floatingProcs->setTitle = Nlm_SetWindowTitle;
  5116.   floatingProcs->getTitle = Nlm_GetWindowTitle;
  5117.   floatingProcs->gainFocus = Nlm_WindowGainFocus;
  5118.   floatingProcs->loseFocus = Nlm_WindowLoseFocus;
  5119.   floatingProcs->sendChar = Nlm_FloatingDrawChar;
  5120.  
  5121.   shadowProcs = &(gphprcsptr [7]);
  5122. #ifdef WIN_MAC
  5123.   shadowProcs->click = Nlm_PlainClick;
  5124.   shadowProcs->key = Nlm_NormalKey;
  5125.   shadowProcs->draw = Nlm_NormalDraw;
  5126.   shadowProcs->idle = Nlm_NormalIdle;
  5127. #endif
  5128.   shadowProcs->show = Nlm_ShowNormal;
  5129.   shadowProcs->hide = Nlm_HideWindow;
  5130.   shadowProcs->activate = Nlm_NormalActivate;
  5131.   shadowProcs->deactivate = Nlm_NormalDeactivate;
  5132.   shadowProcs->remove = Nlm_RemoveWindow;
  5133.   shadowProcs->select = Nlm_PlainSelect;
  5134.   shadowProcs->linkIn = Nlm_LinkIn;
  5135.   shadowProcs->adjustPrnt = Nlm_AdjustWindow;
  5136.   shadowProcs->setTitle = Nlm_SetWindowTitle;
  5137.   shadowProcs->getTitle = Nlm_GetWindowTitle;
  5138.   shadowProcs->gainFocus = Nlm_WindowGainFocus;
  5139.   shadowProcs->loseFocus = Nlm_WindowLoseFocus;
  5140.   shadowProcs->sendChar = Nlm_NormalDrawChar;
  5141.  
  5142.   plainProcs = &(gphprcsptr [8]);
  5143. #ifdef WIN_MAC
  5144.   plainProcs->click = Nlm_PlainClick;
  5145.   plainProcs->key = Nlm_NormalKey;
  5146.   plainProcs->draw = Nlm_NormalDraw;
  5147.   plainProcs->idle = Nlm_NormalIdle;
  5148. #endif
  5149.   plainProcs->show = Nlm_ShowNormal;
  5150.   plainProcs->hide = Nlm_HideWindow;
  5151.   plainProcs->activate = Nlm_NormalActivate;
  5152.   plainProcs->deactivate = Nlm_NormalDeactivate;
  5153.   plainProcs->remove = Nlm_RemoveWindow;
  5154.   plainProcs->select = Nlm_PlainSelect;
  5155.   plainProcs->linkIn = Nlm_LinkIn;
  5156.   plainProcs->adjustPrnt = Nlm_AdjustWindow;
  5157.   plainProcs->setTitle = Nlm_SetWindowTitle;
  5158.   plainProcs->getTitle = Nlm_GetWindowTitle;
  5159.   plainProcs->gainFocus = Nlm_WindowGainFocus;
  5160.   plainProcs->loseFocus = Nlm_WindowLoseFocus;
  5161.   plainProcs->sendChar = Nlm_NormalDrawChar;
  5162.  
  5163.   desktopProcs = &(gphprcsptr [9]);
  5164. #ifdef WIN_MAC
  5165.   desktopProcs->click = Nlm_DesktopClick;
  5166.   desktopProcs->key = Nlm_DesktopKey;
  5167. #endif
  5168.   desktopProcs->show = Nlm_ShowNormal;
  5169.   desktopProcs->hide = Nlm_HideWindow;
  5170.   desktopProcs->remove = Nlm_RemoveWindow;
  5171.   desktopProcs->select = Nlm_DesktopSelect;
  5172.   desktopProcs->linkIn = Nlm_LinkIn;
  5173.  
  5174.   systemProcs = &(gphprcsptr [10]);
  5175. #ifdef WIN_MAC
  5176.   systemProcs->click = Nlm_SystemClick;
  5177.   systemProcs->draw = Nlm_NormalDraw;
  5178. #endif
  5179.   systemProcs->show = Nlm_ShowNormal;
  5180.   systemProcs->hide = Nlm_HideWindow;
  5181.   systemProcs->remove = Nlm_RemoveWindow;
  5182.   systemProcs->select = Nlm_NormalSelect;
  5183.   systemProcs->linkIn = Nlm_LinkIn;
  5184. }
  5185.